Skip to content

Errors

You can have control over the errors that occur during the execution of a task, mapping information such as code tracing, screenshots and files.

BotCity Orchestrator

You can view the Errors functionality directly on the BotCity Orchestrator platform.

See more at:

Create a simple error

A simple error consists of capturing only the most basic information when an error occurs.

To log an error with the SDK, you need the following information:

  • Task ID: Reference of the task that will emit the error.
  • Exception: Information captured from the code within try/except blocks.

See an example of simple error capturing:

try:
    div = 0 / 0
except Exception as error:
    maestro.error(
        task_id=<TASK_ID>, 
        exception=error
    )
try {
    int div = 0/0;
} catch (Exception error) {
    maestro.createError(<TASK_ID>, error, null, null, null);
}
try {
    eval("hoo bar");
} catch (error) {
    await maestro.createError(<TASK_ID>, error)
}
try {
    eval("hoo bar");
} catch (error: any) {
    await maestro.createError(<TASK_ID>, error)
}
try {
    throw new Exception("test");
} catch (Exception ex) {
    await instance.CreateErrorAsync(ex, <TASK_ID>);
}

Create a custom error

You can customize the information that will be sent to the BotCity Orchestrator, including optional parameters in the error capture.

To log a complete error with the SDK, you need the following information:

  • Task ID: Reference of the task that will emit the error.
  • Exception: Information captured from the code within try/except blocks.
  • Screenshot: (optional) Path where the image was saved.
  • Tags: (optional) Information in key/value format stored as text.
  • Attachments: (optional) List of paths where the files were saved.

Screenshot

It is possible to add a screenshot of the screen at the moment the error occurs, passing the path where the image was saved.

How to save a screenshot?

You can use the screenshot saving method for Desktop and web automations with the BotCity Frameworks.

See how to use it at:

See an example of an error with a screenshot:

try:
    div = 0 / 0
except Exception as error:
    file_path = '/home/test/screenshot.png'
    maestro.error(
        task_id=<TASK_ID>, 
        exception=error, 
        screenshot=file_path
    )
try {
    int div = 0/0;
} catch (Exception error) {        
    File screenshot = new File("/home/test/screenshot.png");
    maestro.createError(<TASK_ID>, error, screenshot, null, null);
}
try {
    eval("hoo bar");
} catch (error) {
    const file_path = '/home/test/screenshot.png'
    await maestro.createError(<TASK_ID>, error, {}, file_path)
}
try {
    eval("hoo bar");
} catch (error: any) {
    const file_path: string = '/home/test/screenshot.png'
    await maestro.createError(<TASK_ID>, error, {}, file_path)
}
try {
    throw new Exception("test");
} catch (Exception ex) {
    string filepath = "/home/test/screenshot.png";
    await instance.CreateErrorAsync(ex, <TASK_ID>, filepath);
}

Customizable tags

The default tags captured are the following:

  • User: Username that triggered the task.
  • Host: Name of the environment where the task ran.
  • Operating System: Name of the environment's operating system.
  • OS Version: Version of the environment's operating system.
  • Language version: Version of the language used in the process.

In addition, you can add custom tags with information that is relevant in case of error, in key/value format.

See an example of an error with additional tags:

try:
    div = 0 / 0
except Exception as error:
    tags = {
        "key_1": "value_1",
        "key_2": "value_2",
        "key_3": "value_3",
    }

    maestro.error(
        task_id=<TASK_ID>, 
        exception=error, 
        tags=tags
    )
try {
    int div = 0/0;
} catch (Exception error) {
    Map<String, Object> tags = new HashMap<>();
    tags.put("custom", "tag");

    maestro.createError(<TASK_ID>, error, null, tags, null);
}
try {
    eval("hoo bar");
} catch (error) {
    await maestro.createError(<TASK_ID>, error, {"custom": "tag"})
}
try {
    eval("hoo bar");
} catch (error: any) {
    await maestro.createError(<TASK_ID>, error, {"custom": "tag"})
}
try {
    throw new Exception("test");
} catch (Exception ex) {
    Dictionary<string, object> additionalTags = new Dictionary<string, object>
    {
        { "custom", "tag" },
    };
    await instance.CreateErrorAsync(ex, <TASK_ID>, null, additionalTags);
}

File attachments

You can attach a list of files that make it easier to understand and fix errors when they occur. These files can be of any type.

By default, the file containing the project's dependencies and their versions is attached to the error. You can add extra files by creating a list with the paths of the files to be sent.

File examples

It can be useful to attach:

  • Extra images
  • Code logs
  • Files used during the process.

See an example of an error with file attachments:

try:
    div = 0 / 0
except Exception as error:
    attachments = [
        '/home/test/error.png',
        '/home/test/process.log',
        '/home/test/test.txt'
    ]
    maestro.error(
        task_id=<TASK_ID>, 
        exception=error, 
        attachments=attachments
    )
try {
    int div = 0/0;
} catch (Exception error) {
    List<File> attachments = new ArrayList<>();
    attachments.add(new File("/home/test/error.png"));
    attachments.add(new File("/home/test/process.log"));
    attachments.add(new File("/home/test/test.txt"));

    maestro.createError(<TASK_ID>, error, null, null, attachments);
}
try {
    eval("hoo bar");
} catch (error) {
    const attachments = ['/home/test/error.png', '/home/test/process.log', '/home/test/test.txt']
    await maestro.createError(<TASK_ID>, error, {}, '', attachments)
}
try {
    eval("hoo bar");
} catch (error: any) {
    const attachments: string[] = ['/home/test/error.png', '/home/test/process.log', '/home/test/test.txt']
    await maestro.createError(<TASK_ID>, error, {}, '', attachments)
}
try {
    throw new Exception("test");
} catch (Exception ex) {
    List<string> attachments = ["/home/test/error.png", "/home/test/process.log", "/home/test/test.txt"];
    await instance.CreateErrorAsync(ex, <TASK_ID>, "", null, attachments);
}