Skip to content

Error Handling Interfaces

Introduction

Error Handling Interfaces:
Provides user log recording and error/warning signal sending to the UI, used to record status and report anomalies during task execution.

PurposePython
Log Message
Clear Log Files
Raise Error Signal
Raise Warning Signal

Log Management

Python Interface

log_message(message, logger='default', include_timestamp=False)

Function Description
Write a message to a user log file. Log files are automatically named with a timestamp: {logger}_{YYYYMMDD_HHMMSS}.log, saved to /root/data/daystar_api/user_logs/.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
messagestrRequiredThe log message content to record.
loggerstr'default'Logger name, used as the log filename prefix.
include_timestampboolFalseIf True, include a timestamp in the log content.

Return Value

TypeDescription
boolTrue indicates logging succeeded.

Example

python
from daystar_api.lowlevel_skills import log_message

log_message("Task started")
log_message("Processing item 1", logger="process_log", include_timestamp=True)

clear_log(logger_name='', log_dir='/root/data/daystar_api/user_logs/')

Function Description
Clear user log files. Can clear all logs or only logs for a specific logger. This function does not require API initialization.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
logger_namestr''If specified, only delete log files for this logger; if empty, delete all log files.
log_dirstr'/root/data/daystar_api/user_logs/'Log directory path.

Return Value

TypeDescription
intNumber of log files deleted.

Example

python
from daystar_api.lowlevel_skills import clear_log

# Delete all log files
deleted = clear_log()
print(f"Deleted {deleted} log files")

# Delete only logs for a specific logger
deleted = clear_log("my_task")

Error and Warning Handling

Python Interface

raise_error(message)

Function Description
Send an error signal to the UI. The error message will be displayed in the interface.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
messagestrRequiredError message content.

Return Value

TypeDescription
RaiseErrorResponsestate.code == 0 indicates the signal was sent successfully.

Example

python
from daystar_api.lowlevel_skills import raise_error

response = raise_error("Failed to connect to sensor")
if response.state.code == 0:
    print("Error signal sent to UI")

raise_warn(message)

Function Description
Send a warning signal to the UI. The warning message will be displayed in the interface.

Parameter Description

Parameter NameTypeRequired/DefaultDescription
messagestrRequiredWarning message content.

Return Value

TypeDescription
RaiseWarnResponsestate.code == 0 indicates the signal was sent successfully.

Example

python
from daystar_api.lowlevel_skills import raise_warn

response = raise_warn("Battery below 20%, please charge soon")
if response.state.code == 0:
    print("Warning signal sent to UI")