libyang  2.1.148
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Error information

Data Structures

struct  ly_err_item
 Libyang full error structure. More...
 

Enumerations

enum  LY_ERR {
  LY_SUCCESS = 0, LY_EMEM, LY_ESYS, LY_EINVAL,
  LY_EEXIST, LY_ENOTFOUND, LY_EINT, LY_EVALID,
  LY_EDENIED, LY_EINCOMPLETE, LY_ERECOMPILE, LY_ENOT,
  LY_EOTHER, LY_EPLUGIN = 128
}
 libyang's error codes returned by the libyang functions. More...
 
enum  LY_VECODE {
  LYVE_SUCCESS = 0, LYVE_SYNTAX, LYVE_SYNTAX_YANG, LYVE_SYNTAX_YIN,
  LYVE_REFERENCE, LYVE_XPATH, LYVE_SEMANTICS, LYVE_SYNTAX_XML,
  LYVE_SYNTAX_JSON, LYVE_DATA, LYVE_OTHER
}
 libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set to the appropriate LY_VECODE value. More...
 

Functions

LIBYANG_API_DECL void ly_err_clean (struct ly_ctx *ctx, struct ly_err_item *eitem)
 Free error structures from a context. More...
 
LIBYANG_API_DECL struct
ly_err_item
ly_err_first (const struct ly_ctx *ctx)
 Get the first (thread, context-specific) generated error structure. More...
 
LIBYANG_API_DECL struct
ly_err_item
ly_err_last (const struct ly_ctx *ctx)
 Get the latest (thread, context-specific) generated error structure. More...
 
LIBYANG_API_DECL void ly_err_print (const struct ly_ctx *ctx, struct ly_err_item *eitem)
 Print the error structure as if just generated. More...
 
LIBYANG_API_DECL const char * ly_errapptag (const struct ly_ctx *ctx)
 Get the last (thread, context-specific) error-app-tag if there was a specific one defined in the module for the last error. More...
 
LIBYANG_API_DECL LY_ERR ly_errcode (const struct ly_ctx *ctx)
 Get the last (thread, context-specific) error code. More...
 
LIBYANG_API_DECL const char * ly_errmsg (const struct ly_ctx *ctx)
 Get the last (thread, context-specific) error message. If the coresponding module defined a specific error message, it will be used instead the default one. More...
 
LIBYANG_API_DECL const char * ly_errpath (const struct ly_ctx *ctx)
 Get the last (thread, context-specific) path of the element where was an error. More...
 
LIBYANG_API_DECL const char * ly_last_errmsg (void)
 Get the last (thread-specific) error message. More...
 
LIBYANG_API_DECL const char * ly_strerrcode (LY_ERR err)
 Get human-readable error message for an error code. More...
 
LIBYANG_API_DECL const char * ly_strvecode (LY_VECODE vecode)
 Get human-readable error message for a validation error code. More...
 
LIBYANG_API_DECL LY_VECODE ly_vecode (const struct ly_ctx *ctx)
 Get the last (thread, context-specific) validation error code. More...
 

Detailed Description

Structures and functions to allow error information processing.


Data Structure Documentation

struct ly_err_item

Libyang full error structure.

Definition at line 296 of file log.h.

Data Fields
char * apptag

error-app-tag, if any

LY_LOG_LEVEL level

error (message) log level

char * msg

error message

struct ly_err_item * next

next error item

LY_ERR no

error code

char * path

error path that caused the error, if any

struct ly_err_item * prev

previous error item, points to the last item for the ifrst item

LY_VECODE vecode

validation error code, if any

Enumeration Type Documentation

enum LY_ERR

libyang's error codes returned by the libyang functions.

Enumerator
LY_SUCCESS 

no error, not set by functions, included just to complete LY_ERR enumeration

LY_EMEM 

Memory allocation failure

LY_ESYS 

System call failure

LY_EINVAL 

Invalid value

LY_EEXIST 

Item already exists

LY_ENOTFOUND 

Item does not exists

LY_EINT 

Internal error

LY_EVALID 

Validation failure

LY_EDENIED 

Operation is not allowed

LY_EINCOMPLETE 

The operation did not fail, but for some reason it was not possible to finish it completely. According to the specific use case, the caller is usually supposed to perform the operation again.

LY_ERECOMPILE 

The operation did not fail, but requires context recompilation before it can be completed. According to the specific use case, the caller should react appropriately.

LY_ENOT 

Negative result

LY_EOTHER 

Unknown error

LY_EPLUGIN 

Error reported by a plugin - the highest bit in the first byte is set. This value is used ORed with one of the other LY_ERR value and can be simply masked.

Definition at line 251 of file log.h.

enum LY_VECODE

libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set to the appropriate LY_VECODE value.

Enumerator
LYVE_SUCCESS 

no error

LYVE_SYNTAX 

generic syntax error

LYVE_SYNTAX_YANG 

YANG-related syntax error

LYVE_SYNTAX_YIN 

YIN-related syntax error

LYVE_REFERENCE 

invalid referencing or using an item

LYVE_XPATH 

invalid XPath expression

LYVE_SEMANTICS 

generic semantic error

LYVE_SYNTAX_XML 

XML-related syntax error

LYVE_SYNTAX_JSON 

JSON-related syntax error

LYVE_DATA 

YANG data does not reflect some of the module restrictions

LYVE_OTHER 

Unknown error

Definition at line 278 of file log.h.

Function Documentation

LIBYANG_API_DECL void ly_err_clean ( struct ly_ctx ctx,
struct ly_err_item eitem 
)

Free error structures from a context.

If eitem is not set, free all the error structures.

Parameters
[in]ctxRelative context.
[in]eitemOldest error structure to remove, optional.
LIBYANG_API_DECL struct ly_err_item* ly_err_first ( const struct ly_ctx ctx)

Get the first (thread, context-specific) generated error structure.

Parameters
[in]ctxRelative context.
Returns
The first error structure (can be NULL), do not modify!
LIBYANG_API_DECL struct ly_err_item* ly_err_last ( const struct ly_ctx ctx)

Get the latest (thread, context-specific) generated error structure.

Parameters
[in]ctxRelative context.
Returns
The last error structure (can be NULL), do not modify!
LIBYANG_API_DECL void ly_err_print ( const struct ly_ctx ctx,
struct ly_err_item eitem 
)

Print the error structure as if just generated.

Parameters
[in]ctxOptional context to store the message in.
[in]eitemError item structure to print.
LIBYANG_API_DECL const char* ly_errapptag ( const struct ly_ctx ctx)

Get the last (thread, context-specific) error-app-tag if there was a specific one defined in the module for the last error.

The app-tag always corresponds to the error message available via ly_errmsg(), so whenever a subsequent error message is printed, the app-tag is erased or rewritten.

Parameters
[in]ctxRelative context.
Returns
Error-app-tag of the last error, empty string if the error-app-tag does not apply to the last error.
LIBYANG_API_DECL LY_ERR ly_errcode ( const struct ly_ctx ctx)

Get the last (thread, context-specific) error code.

Parameters
[in]ctxRelative context.
Returns
LY_ERR value of the last error code.
LIBYANG_API_DECL const char* ly_errmsg ( const struct ly_ctx ctx)

Get the last (thread, context-specific) error message. If the coresponding module defined a specific error message, it will be used instead the default one.

Sometimes, the error message is extended with path of the element where the problem is. The path is available via ly_errpath().

Parameters
[in]ctxRelative context.
Returns
Text of the last error message, empty string if there is no error.
LIBYANG_API_DECL const char* ly_errpath ( const struct ly_ctx ctx)

Get the last (thread, context-specific) path of the element where was an error.

The path always corresponds to the error message available via ly_errmsg(), so whenever a subsequent error message is printed, the path is erased or rewritten. The path reflects the type of the processed tree - data path for data tree functions and schema path in case of schema tree functions. In case of processing YIN schema or XML data, the path can be just XML path. In such a case, the corresponding ly_vecode (value 1-3) is set.

Parameters
[in]ctxRelative context.
Returns
Path of the error element, empty string if error path does not apply to the last error.
LIBYANG_API_DECL const char* ly_last_errmsg ( void  )

Get the last (thread-specific) error message.

ly_errmsg() should be used instead of this function but this one is useful for getting errors from functions that do not have any context accessible. Or as a simple unified logging API.

Returns
Last generated error message.
LIBYANG_API_DECL const char* ly_strerrcode ( LY_ERR  err)

Get human-readable error message for an error code.

Parameters
[in]errError code.
Returns
String error message.
LIBYANG_API_DECL const char* ly_strvecode ( LY_VECODE  vecode)

Get human-readable error message for a validation error code.

Parameters
[in]vecodeValidation error code.
Returns
String error message.
LIBYANG_API_DECL LY_VECODE ly_vecode ( const struct ly_ctx ctx)

Get the last (thread, context-specific) validation error code.

This value is set only if ly_errno is LY_EVALID.

Parameters
[in]ctxRelative context.
Returns
Validation error code.