Skip to content

Commit

Permalink
sqapi: more meaningfull error messages when tool fails
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@7918 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
Dwachs committed Oct 19, 2016
1 parent 59facd2 commit ada8d5a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 24 deletions.
8 changes: 4 additions & 4 deletions script/api/api_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ SQInteger command_constructor(HSQUIRRELVM vm)
SQInteger param<call_tool_init>::push(HSQUIRRELVM vm, call_tool_init v)
{
if (v.error) {
return *v.error ? sq_raise_error(vm, v.error) : SQ_ERROR;
return sq_raise_error(vm, *v.error ? v.error : "Strange error occured");
}
// create tool, if necessary, delete on exit
std::auto_ptr<tool_t> our_tool;
Expand All @@ -57,7 +57,7 @@ SQInteger param<call_tool_init>::push(HSQUIRRELVM vm, call_tool_init v)
}
// sanity check
if (player == NULL) {
return SQ_ERROR;
return sq_raise_error(vm, "Called tool with player == null");
}
// check if calling suspendable tools is blocked
if (const char* blocker = env_t::networkmode ? sq_get_suspend_blocker(vm) : NULL) {
Expand Down Expand Up @@ -160,7 +160,7 @@ tool_t * call_tool_base_t::create_tool()
SQInteger param<call_tool_work>::push(HSQUIRRELVM vm, call_tool_work v)
{
if (v.error) {
return *v.error ? sq_raise_error(vm, v.error) : SQ_ERROR;
return sq_raise_error(vm, *v.error ? v.error : "Strange error occured");
}
// create tool, if necessary, delete on exit
std::auto_ptr<tool_t> our_tool;
Expand All @@ -184,7 +184,7 @@ SQInteger param<call_tool_work>::push(HSQUIRRELVM vm, call_tool_work v)
}
// sanity check
if (player == NULL) {
return SQ_ERROR;
return sq_raise_error(vm, "Called tool with player == null");
}
uint8 flags = tool->flags; // might be reset by init()

Expand Down
5 changes: 2 additions & 3 deletions script/api/api_convoy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ call_tool_init convoy_set_name(convoi_t *cnv, const char* name)
call_tool_init convoy_set_line(convoi_t *cnv, player_t *player, linehandle_t line)
{
if (!line.is_bound()) {
return call_tool_init(""); // error
return "Invalid line handle provided";
}

// see depot_frame_t::apply_line() and convoi_t::call_convoi_tool()
cbuffer_t buf;
buf.printf("%c,%u,%i", 'l', cnv->self.get_id(), line->get_handle().get_id());
Expand All @@ -140,7 +139,7 @@ call_tool_init convoy_generic_tool(convoi_t *cnv, player_t *player, uint8 cnvtoo
{
char c = (char)cnvtool;
if (strchr("wx", c) == NULL) {
return call_tool_init(""); // error
return "Invalid convoy tool called";
}
// see convoi_t::call_convoi_tool()
cbuffer_t buf;
Expand Down
2 changes: 1 addition & 1 deletion script/api/api_halt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SQInteger halt_export_convoy_list(HSQUIRRELVM vm)
call_tool_init halt_set_name(halthandle_t halt, const char* name)
{
if (!halt.is_bound()) {
return call_tool_init(""); // error
return "Invalid halt provided";
}
return command_rename(halt->get_owner(), 'h', halt.get_id(), name);
}
Expand Down
15 changes: 6 additions & 9 deletions script/api/api_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ bool line_is_valid(linehandle_t line)
return line.is_bound();
}

call_tool_init line_change_schedule(linehandle_t line, player_t *player, schedule_t *sched)
call_tool_init line_change_schedule(simline_t* line, player_t *player, schedule_t *sched)
{
if (line.is_bound() && sched) {
if (sched) {
// build param string (see line_management_gui_t::infowin_event)
cbuffer_t buf;
buf.printf( "g,%i,", line.get_id() );
buf.printf( "g,%i,", line->get_handle().get_id() );
sched->sprintf_schedule( buf );

return call_tool_init(TOOL_CHANGE_LINE | SIMPLE_TOOL, buf, 0, player);
}
return call_tool_init(""); // error
return "Invalid schedule provided";
}

SQInteger line_export_convoy_list(HSQUIRRELVM vm)
Expand All @@ -81,12 +81,9 @@ SQInteger line_export_convoy_list(HSQUIRRELVM vm)
return SQ_ERROR;
}

call_tool_init line_set_name(linehandle_t line, const char* name)
call_tool_init line_set_name(simline_t* line, const char* name)
{
if (!line.is_bound()) {
return call_tool_init(""); // error
}
return command_rename(line->get_owner(), 'l', line.get_id(), name);
return command_rename(line->get_owner(), 'l', line->get_handle().get_id(), name);
}

vector_tpl<linehandle_t> const* generic_get_line_list(HSQUIRRELVM vm, SQInteger index)
Expand Down
6 changes: 3 additions & 3 deletions script/api/api_map_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ void begin_obj_class(HSQUIRRELVM vm, const char* name, const char* base = NULL)
// markers / labels
call_tool_work create_marker(koord pos, player_t* player, const char* text)
{
if (player == NULL || text == NULL) {
return "";
if (text == NULL) {
return "Cannot create label with text == null";
}
return call_tool_work(TOOL_MARKER | GENERAL_TOOL, text, 0, player, koord3d(pos, 0));
}
Expand All @@ -261,7 +261,7 @@ const char* label_get_text(label_t* l)
call_tool_init depot_append_vehicle(depot_t *depot, player_t *player, convoihandle_t cnv, const vehikel_besch_t *besch)
{
if (besch == NULL) {
return call_tool_init(""); // error
return "Invalid vehicle_desc_x provided";
}
// see depot_frame_t::image_from_storage_list: tool = 'a'
// see depot_t::call_depot_tool for command string composition
Expand Down
2 changes: 1 addition & 1 deletion script/api/api_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ call_tool_init player_create_line(player_t *player, waytype_t wt)
{
simline_t::linetype lt = simline_t::get_linetype(wt);
if (lt == simline_t::MAX_LINE_TYPE) {
return call_tool_init("Invalid waytype provided");
return "Invalid waytype provided";
}
// build param string (see schedule_list_gui_t::action_triggered)
cbuffer_t buf;
Expand Down
3 changes: 0 additions & 3 deletions script/api/api_tiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ SQInteger get_object_index(HSQUIRRELVM vm)

call_tool_work tile_remove_object(grund_t* gr, player_t* player, obj_t::typ type)
{
if (player == NULL) {
return "";
}
cbuffer_t buf;
buf.printf("%d", (int)type);
return call_tool_work(TOOL_REMOVER | GENERAL_TOOL, (const char*)buf, 0, player, gr->get_pos());
Expand Down

0 comments on commit ada8d5a

Please sign in to comment.