RT-Thread / RT-Thread/rt-thread

错误码设定和返回规范 | Error code setting and return specification

Open
#7,950 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
12.2k
Forks
5.4k
Avg merge
4d 12h
Merged PRs (30d)
40

Description

1 RT-Thread 有两种错误码

  • 一种是RT-Thread自己的错误码,如 RT_ERRORRT_EINVAL
  • 另一种是POSIX标准错误码 如 ERROREINVAL

若代码、组件是针对POSIX兼容设计的,则使用POSIX标准错误码,否则使用RT-Thread错误码。

例如:AT组件不是POSIX兼容设计,因此使用RT-Thread错误码;DFSv2是POSIX兼容设计,因此采用POSIX错误码。

2 错误码的正负

  • 以函数返回值方式无论POSIX错误码还是RT-Thread错误码都返回负值错误码 (除了 EOKRT_EOK,这俩不用加负号),例如:
    • return -RT_EINVAL;
    • return -EINVAL;
    • return EOK;
    • return RT_EOK;
  • errno=rt_set_errno方式注入错误码,无论POSIX错误码还是RT-Thread错误码都使用正值错误码, 例如:
    • rt_set_errno(EINVAL);
    • rt_set_errno(RT_EINVAL);
    • errno = EINVAL;
    • errno = RT_EINVAL;
    • rt_set_errno(RT_EOK);
    • errno = EOK;

3 相关

https://github.com/RT-Thread/rt-thread/issues/4791


1 RT-Thread has two error codes

  • One is RT-Thread's own error code, such as RT_ERROR, RT_EINVAL, etc.
  • The other is POSIX standard error codes such as ERROR, EINVAL, etc.

If the code and component are designed for POSIX compatibility, use the POSIX standard error code, otherwise use the RT-Thread error code.

For example: AT components are not POSIX compliant, so RT-Thread error codes are used; DFSv2 is POSIX compliant, so POSIX error codes are used.

2 The sign of the error code

  • Regardless of the POSIX error code or the RT-Thread error code, the function returns a negative value error code (except for EOK and RT_EOK, which do not need to be negative), for example:
    • return -RT_EINVAL;
    • return -EINVAL;
    • return EOK;
    • return RT_EOK;
  • Inject error codes with errno= or rt_set_errno, regardless of POSIX error codes or RT-Thread error codes, use positive error codes, for example:
    • rt_set_errno(EINVAL);
    • rt_set_errno(RT_EINVAL);
    • errno = EINVAL;
    • errno = RT_EINVAL;
    • rt_set_errno(RT_EOK);
    • errno = EOK;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the related issue #4791 and comparing its discussion with the AT and DFSv2 examples named here. Check how the documented RT-Thread and POSIX error-code conventions apply across the relevant components; done means the scope and return-versus-errno rules are agreed and recorded.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
documentation, embedded-iot, operating-systems
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.