Skip to content

feature request: Meaningful and unique return codes #884

@fra87

Description

@fra87

Feature Request

At present the functions (I'm mainly focusing on write_x at present) return integer values, but there is an overlapping that does not allow to properly identify the error in case the generic write function is used.

This is not evident from the docs, since there is no overlapping there, but looking at the source code I found that for instance write_formula returns -2 for "Formula can't be None or empty", while write_string uses the same value for "String longer than 32767 characters". write_url and write_rich_string have many indexes in common.

It may be better to switch to a list of common Enum values to be assigned:

from enum import Enum, auto

class ResultCode(Enum):
    SUCCESS = 0
    NOT_SUPPORTED_IN_CONSTANT_MEMORY_MODE = auto()
    ROW_OR_COLUMN_OUTSIDE_WORKSHEET_BOUNDS = auto()
    [...]
    UNKNOWN_ERROR = auto()

then use it like all enums:

if self._check_dimensions(row, col):
    return ResultCode.ROW_OR_COLUMN_OUTSIDE_WORKSHEET_BOUNDS

This way the values will always be unique.

Alternatively (but this is a much less readable solution) the values can be kept, but at least the same value shall not be reused for different meanings

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions