Skip to main content

Error Codes

Complete reference for Argus error codes and their meanings.

Success Codes

CodeValueDescription
ARGUS_SUCCESS0Operation completed successfully
ARGUS_SOULD_EXIT1Program should exit (help/version shown)

Structure Errors

Errors detected during option definition validation:

CodeWhen TriggeredFix
ARGUS_ERROR_DUPLICATE_OPTIONSame short/long name used twiceUse unique option names
ARGUS_ERROR_INVALID_HANDLEROption missing handler functionAdd HANDLER() macro
ARGUS_ERROR_INVALID_DEFAULTDefault value invalid for typeFix default value type
ARGUS_ERROR_INVALID_GROUPGroup definition malformedCheck group syntax
ARGUS_ERROR_INVALID_DEPENDENCYInvalid requires/conflictsFix dependency names
ARGUS_ERROR_INVALID_FLAGInvalid flag for option typeUse correct flags
ARGUS_ERROR_INVALID_POSITIONRequired positional after optionalReorder positionals
ARGUS_ERROR_MALFORMED_OPTIONOption definition incompleteAdd required fields
ARGUS_ERROR_MISSING_HELPNo help option definedAdd HELP_OPTION()

Examples

// ❌ ARGUS_ERROR_DUPLICATE_OPTION
OPTION_STRING('o', "output", HELP("Output file")),
OPTION_INT('o', "count", HELP("Count")) // Same short name

// ❌ ARGUS_ERROR_INVALID_HANDLER
OPTION_STRING('f', "file", HELP("File")) // Missing HANDLER()

// ❌ ARGUS_ERROR_INVALID_POSITION
POSITIONAL_STRING("input", HELP("Input"), FLAGS(FLAG_OPTIONAL)),
POSITIONAL_STRING("output", HELP("Output")) // Required after optional

Parsing Errors

Errors during command-line argument parsing:

CodeWhen TriggeredExample
ARGUS_ERROR_INVALID_ARGUMENTUnknown option provided--unknown-option
ARGUS_ERROR_MISSING_VALUEOption requires value but none given--output (no file)
ARGUS_ERROR_MISSING_REQUIREDRequired option not providedMissing FLAG_REQUIRED option
ARGUS_ERROR_CONFLICTING_OPTIONSConflicting options used together--verbose --quiet
ARGUS_ERROR_INVALID_FORMATValue format incorrect--port abc
ARGUS_ERROR_EXCLUSIVE_GROUPMultiple options from exclusive group--gzip --bzip2
ARGUS_ERROR_INVALID_CHOICEValue not in allowed choices--format pdf
ARGUS_ERROR_INVALID_RANGENumeric value out of range--port 99999

User Messages

$ ./app --unknown
app: Unknown option: '--unknown'

$ ./app --output
app: Missing value for option: '--output'

$ ./app --port abc
app: Invalid value 'abc': expected number

$ ./app --count 150
app: Value 150 is out of range [1, 100]

Execution Errors

Errors during subcommand execution:

CodeWhen TriggeredFix
ARGUS_ERROR_NO_COMMANDargus_exec() with no commandCheck argus_has_command() first

Internal Errors

System-level errors:

CodeWhen TriggeredCause
ARGUS_ERROR_MEMORYMemory allocation failedOut of memory
ARGUS_ERROR_INTERNALInternal library errorBug in Argus
ARGUS_ERROR_UNSUPPORTEDFeature not supportedCompile-time option disabled
ARGUS_ERROR_INVALID_VALUEGeneric value errorVarious validation failures
ARGUS_ERROR_STACK_OVERFLOWToo many errors/subcommandsReduce nesting

Error Handling

Automatic Handling

// Parsing errors are automatically displayed
if (argus_parse(&argus, argc, argv) != ARGUS_SUCCESS) {
return 1; // Error already printed with suggestion
}

Manual Error Reporting

// In custom handlers/validators
ARGUS_PARSING_ERROR(argus, "Invalid endpoint format '%s'", value);
return ARGUS_ERROR_INVALID_VALUE;

Validation Errors

Specific validation error patterns:

Range Validation

OPTION_INT('p', "port", VALIDATOR(V_RANGE(1, 65535)))
// Error: "Value 99999 is out of range [1, 65535]"

Length Validation

OPTION_STRING('u', "user", VALIDATOR(V_LENGTH(3, 20)))
// Error: "Value 2 is out of length [3, 20]"

Count Validation

OPTION_ARRAY_STRING('t', "tags", VALIDATOR(V_COUNT(1, 5)))
// Error: "Values count 6 is out of [1, 5]"

Regex Validation

OPTION_STRING('e', "email", VALIDATOR(V_REGEX(ARGUS_RE_EMAIL)))
// Error: "Invalid value 'bad-email': Enter email: user@example.com"

Choice Validation

OPTION_STRING('f', "format", VALIDATOR(V_CHOICE_STR("json", "xml")))
// Error: "Cannot be set to 'pdf'. Choose from ["json", "xml"]"

Error Prevention

Good Practices

// ✅ Clear option names
OPTION_STRING('c', "config", HELP("Configuration file"))

// ✅ Sensible defaults
OPTION_INT('p', "port", DEFAULT(8080), VALIDATOR(V_RANGE(1, 65535)))

// ✅ Clear help text
OPTION_STRING('o', "output", HELP("Output file path"))

// ✅ Proper validation
OPTION_STRING('e', "email", VALIDATOR(V_REGEX(ARGUS_RE_EMAIL)))

Common Mistakes

// ❌ Missing help
OPTION_STRING('f', "file") // No HELP()

// ❌ Invalid default
OPTION_INT('p', "port", DEFAULT("8080")) // String default for int

// ❌ Missing validation
OPTION_INT('p', "port") // No range check

Error Code Constants

typedef enum argus_error_type_e {
// Success
ARGUS_SUCCESS = 0,
ARGUS_SOULD_EXIT,

// Structure errors (1-10)
ARGUS_ERROR_DUPLICATE_OPTION,
ARGUS_ERROR_INVALID_HANDLER,
ARGUS_ERROR_INVALID_DEFAULT,
ARGUS_ERROR_INVALID_GROUP,
ARGUS_ERROR_INVALID_DEPENDENCY,
ARGUS_ERROR_INVALID_FLAG,
ARGUS_ERROR_INVALID_POSITION,
ARGUS_ERROR_MALFORMED_OPTION,
ARGUS_ERROR_MISSING_HELP,

// Parsing errors (11-20)
ARGUS_ERROR_INVALID_ARGUMENT,
ARGUS_ERROR_MISSING_VALUE,
ARGUS_ERROR_MISSING_REQUIRED,
ARGUS_ERROR_CONFLICTING_OPTIONS,
ARGUS_ERROR_INVALID_FORMAT,
ARGUS_ERROR_EXCLUSIVE_GROUP,
ARGUS_ERROR_INVALID_CHOICE,
ARGUS_ERROR_INVALID_RANGE,

// Execution errors (21-25)
ARGUS_ERROR_NO_COMMAND,

// Internal errors (26-30)
ARGUS_ERROR_MEMORY,
ARGUS_ERROR_INTERNAL,
ARGUS_ERROR_UNSUPPORTED,
ARGUS_ERROR_INVALID_VALUE,
ARGUS_ERROR_STACK_OVERFLOW
} argus_error_type_t;