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.
| Purpose | Python |
|---|---|
| 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 Name | Type | Required/Default | Description |
|---|---|---|---|
message | str | Required | The log message content to record. |
logger | str | 'default' | Logger name, used as the log filename prefix. |
include_timestamp | bool | False | If True, include a timestamp in the log content. |
Return Value
| Type | Description |
|---|---|
bool | True indicates logging succeeded. |
Example
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 Name | Type | Required/Default | Description |
|---|---|---|---|
logger_name | str | '' | If specified, only delete log files for this logger; if empty, delete all log files. |
log_dir | str | '/root/data/daystar_api/user_logs/' | Log directory path. |
Return Value
| Type | Description |
|---|---|
int | Number of log files deleted. |
Example
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 Name | Type | Required/Default | Description |
|---|---|---|---|
message | str | Required | Error message content. |
Return Value
| Type | Description |
|---|---|
RaiseErrorResponse | state.code == 0 indicates the signal was sent successfully. |
Example
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 Name | Type | Required/Default | Description |
|---|---|---|---|
message | str | Required | Warning message content. |
Return Value
| Type | Description |
|---|---|
RaiseWarnResponse | state.code == 0 indicates the signal was sent successfully. |
Example
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")