help desk
You may want to be able to retrace each step of you algorithm. For this you may create new errors along the way.
Take this package example
%include_once "/extenso/module/sed/error/package/p_error.sn"; package my_package function my_function(my_param) // Validate input parameters if !my_param then return sed_error::new_error(-1, current_function() .+ " - Error: Parameter `my_param` cannot be empty.", my_param); endif [...] // Get stuff sql_rs = sql(error: false, " SELECT * FROM my_table WHERE uid = '?' ", my_param); // Validate query output if sql_rs.error then return sed_error::new_error(-1, current_function() .+ " - Error: Query failed", sql_rs); endif if !sql_rs.nbrows then return sed_error::new_error(-1, current_function() .+ " - Error: No entry found", sql_rs); endif return mysql_rs.rows; endf endp
Take this resource
// file: r_my_resource.sn %include_once "/extenso/module/sed/error/package/p_error.sn"; %include_once "my_package.sn"; function main(cgidata) switch cgidata.operation do case "my_case_1": my_result = my_package::my_function(cgidata.my_param); // You can create a new error by passing the previous error as a `previous` optional named parameter if my_result.type() eq "sed_error::Error" then // Create a new error by providing the previous error return sed_error::new_error( -1, current_function() .+ "r_my_ressource::my_case_1 - Error: Could not get a valid result", cgidata, previous: my_result // <-- By adding this, you will link your previous error with the new one ); endif // No error return my_result; endc case "my_case_2": my_result = my_package::my_function(cgidata.my_param); // If you do not want to register this step in the stack, you can simply transfer the original error if my_result.type() eq "sed_error::Error" then return my_result; endif // No error return my_result; endc ends endf cgidata = cgidata(); main(cgidata); // Will output a sed_error::Error or the content of the page
Stack rendering
By default, your error will contains an attribute stack
which contains the list or error created along the way. Behind the scene, the function .print()
is called when creating a new error. In prod, the print function will cleanup the error by removing all internal information. Only the uid_error
and the errcode
will be shown. In stage, it will add an attribute error_url
that will bring directly to the error page. This is handled automatically.
Error page
An interface is availble to view an error with its full stack in a readable UI.
If the error_url
is part of the error sent to the FE, the popup will show a "View error" link that will bring you directly to this error's page.If a user gives you an error code, you can go to the error page by using one of those two methods:
Note that selecting an error that is in the middle of a stack will always show you the first error with the whole stack.
Error example
In prod
{ "errcode": -1, "uid_error": 83758 }
In stage
{ "errcode": -1, "errmesg": "r_my_ressource::my_case_1 - Error: Could not get a valid result", "stack": [ { "errcode": "-1", "errmesg": "my_package::my_function - Error: Query failed", "content": {...}, "uid_error": "83757", "uid_previous": "" } ], "content": {...}, "uid_error": 83758, "uid_previous": 83757, "error_url": ".../extenso/secure/module/sed/error/en/print.snc?uid=83758" }
Limitation - Safeguards
As a failsafe, the stack can contain a maximum of 20 items. If you need to increase this number, you can supercharge the package `sed_error::stack_limit` after the `sed_error` include:
%include_once "/extenso/module/sed/error/package/p_error.sn"; sed_error::stack_limit = 100; // Default: 20 [...]
Répondu le : 2023-06-07 10:34:00