Error

group harp_error

With a few exceptions almost all HARP functions return an integer that indicate whether the function was able to perform its operations successfully. The return value will be 0 on success and -1 otherwise. In case you get a -1 you can look at the global variable harp_errno for a precise error code. Each error code and its meaning is described in this section. You will also be able to retrieve a character string with an error description via the harp_errno_to_string() function. This function will return either the default error message for the error code, or a custom error message. A custom error message will only be returned if the error code you pass to harp_errno_to_string() is equal to the last error that occurred and if this last error was set with a custom error message. The HARP error state can be set with the harp_set_error() function.

Error values

HARP_SUCCESS (0)

Success (no error).

HARP_ERROR_OUT_OF_MEMORY (-1)

Out of memory.

HARP_ERROR_HDF4 (-100)

An error occurred in the HDF4 library.

HARP_ERROR_NO_HDF4_SUPPORT (-101)

No HDF4 support built into HARP.

HARP_ERROR_HDF5 (-102)

An error occurred in the HDF5 library.

HARP_ERROR_NO_HDF5_SUPPORT (-103)

No HDF5 support built into HARP.

HARP_ERROR_NETCDF (-104)

An error occurred in the netCDF library.

HARP_ERROR_CODA (-105)

An error occurred in the CODA library.

HARP_ERROR_FILE_NOT_FOUND (-200)

File not found.

HARP_ERROR_FILE_OPEN (-201)

Could not open file.

HARP_ERROR_FILE_CLOSE (-202)

Could not close file.

HARP_ERROR_FILE_READ (-203)

Could not read data from file.

HARP_ERROR_FILE_WRITE (-204)

Could not write data to file.

HARP_ERROR_INVALID_ARGUMENT (-300)

Invalid argument.

HARP_ERROR_INVALID_INDEX (-301)

Invalid index argument.

HARP_ERROR_INVALID_NAME (-302)

Invalid name argument.

HARP_ERROR_INVALID_FORMAT (-303)

Invalid format in argument.

HARP_ERROR_INVALID_DATETIME (-304)

Invalid date/time argument.

HARP_ERROR_INVALID_TYPE (-305)

Invalid type.

HARP_ERROR_ARRAY_NUM_DIMS_MISMATCH (-308)

Incorrect number of dimensions argument.

HARP_ERROR_ARRAY_OUT_OF_BOUNDS (-309)

Array index out of bounds.

HARP_ERROR_VARIABLE_NOT_FOUND (-310)

Variable not found.

HARP_ERROR_UNIT_CONVERSION (-400)

An error occured in the unit conversion.

HARP_ERROR_OPERATION (-500)

There was an error detected in the product operations.

HARP_ERROR_OPERATION_SYNTAX (-501)

There is a syntax error in the string defining the product operations.

HARP_ERROR_IMPORT (-600)

An error occured during product import.

HARP_ERROR_EXPORT (-601)

An error occured during product export.

HARP_ERROR_INGESTION (-700)

There was an error in the ingestion of a data product.

HARP_ERROR_INGESTION_OPTION_SYNTAX (-701)

There was a syntax error in the ingestion option.

HARP_ERROR_INVALID_INGESTION_OPTION (-702)

The ingestion option is not valid for this ingestion.

HARP_ERROR_INVALID_INGESTION_OPTION_VALUE (-703)

The ingestion option has value that is not valid for this option.

HARP_ERROR_UNSUPPORTED_PRODUCT (-800)

The data product is not supported by the import or ingestion module.

HARP_ERROR_NO_DATA (-900)

The operation resulted in an ‘empty’ product.

Functions

void harp_add_error_message(const char *message, ...)

Extend the current error message with additional information.

Parameters
  • message: Error message using printf() format.

void harp_set_error(int err, const char *message, ...)

Set the error value and optionally set a custom error message. If message is NULL then the default error message for the error number will be used.

Parameters
  • err: Value of harp_errno.
  • message: Optional error message using printf() format.

const char *harp_errno_to_string(int err)

Returns a string with the description of the HARP error. If err equals the current HARP error status then this function will return the error message that was last set using harp_set_error(). If the error message argument to harp_set_error() was NULL or if err does not equal the current HARP error status then the default error message for err will be returned.

Return
String with a description of the HARP error.
Parameters

int harp_report_warning(const char *message, ...)

Report a warning message The warning message will be passed on to the current warning handler that was set by harp_set_warning_handler(). If no warning handler was set, then this function will do nothing (and return the value 0). The convention is for warning messages to start with a non-capital letter and not contain end-of-line characters. This is similar to the error messages that can be set with harp_set_error(). Printing of line endings, if these are needed, should be performed by the warning handler.

Return
Return code from the warning handler.
Parameters
  • message: Warning message using printf() format.

int harp_get_warning_handler(int (**print)(const char *, va_list ap))

Get a reference to the current handler for warning messages If no warning handler was set, the NULL pointer will be returned.

Return
  • 0, Succes.
  • -1, Error occurred (check harp_errno).
Parameters
  • print: Pointer to the variable in which the reference to the vprintf compatible function will be stored

int harp_set_warning_handler(int (*print)(const char *, va_list ap))

Set handler for warning messages The print function parameter should be a function that resembles vprintf(). The most common case is to provide a function that prints a ‘WARNING’ prefix, prints the message, and adds a newline. For example:

static int print_warning(const char *message, va_list ap)
{
   int result;
   printf("WARNING: ");
   result = vprintf(message, ap);
   printf("\n");
   return result;
}
harp_set_warning_handler(print_warning);
The handler function will get called whenever harp_report_warning() is called (several functions inside the HARP library may call harp_report_warning() to report on certain warning conditions). The warning handler can be set before a call to harp_init() is made.
Return
  • 0, Succes.
  • -1, Error occurred (check harp_errno).
Parameters
  • print: Reference to a vprintf compatible function.

Variables

int harp_errno

Variable that contains the error type. If no error has occurred the variable contains HARP_SUCCESS (0).