Skip to content

Commit dd81038

Browse files
author
Andrew D. France
committed
Initial commit of cl-win32-errors library
0 parents  commit dd81038

24 files changed

+3463
-0
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# .github/workflows/ci.yml
2+
3+
name: CI
4+
5+
on:
6+
push:
7+
branches: [ "main", "master" ]
8+
pull_request:
9+
branches: [ "main", "master" ]
10+
11+
jobs:
12+
test:
13+
runs-on: windows-latest
14+
15+
env:
16+
LISP: sbcl-bin
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
- name: Setup Common Lisp
22+
uses: 40ants/setup-lisp@v4
23+
with:
24+
asdf-system: cl-win32-errors
25+
26+
- name: Install Dependencies & Run Tests
27+
shell: lispsh -eo pipefail {0}
28+
run: |
29+
ros install fiveam
30+
ros --eval "(asdf:test-system :cl-win32-errors)" --quit

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*.fasl
2+
*.lib
3+
*.x86f
4+
*.x64f
5+
*.ax64f
6+
*.lx64f
7+
*.aarch64f
8+
*.ppcf
9+
*.dfsl
10+
*.lf
11+
*~
12+
#*#
13+
.*.swp
14+
.roswell/
15+
.idea/
16+
.vscode/
17+
*.elc
18+
.qlot/
19+
qlfile.lock

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/ "null").
6+
7+
## [1.0.0] - 2025-07-25
8+
9+
### Added
10+
11+
- Initial release of `cl-win32-errors`.
12+
13+
- A comprehensive mapping of over 2,300 Windows API error codes to their symbolic names and descriptions.
14+
15+
- Core API functions (`get-error-details`, `format-error-message`) for error code translation.
16+
17+
- A `win32-error` condition system with accessors for idiomatic Lisp error handling.
18+
19+
- ASDF system definitions for the library (`cl-win32-errors`) and its test suite (`cl-win32-errors/tests`).
20+
21+
- Full unit test suite using FiveAM to verify API correctness and data integrity.

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8+
9+
## Our Standards
10+
11+
Examples of behavior that contributes to a positive environment for our community include:
12+
13+
* Demonstrating empathy and kindness toward other people
14+
* Being respectful of differing opinions, viewpoints, and experiences
15+
* Giving and gracefully accepting constructive feedback
16+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17+
* Focusing on what is best not just for us as individuals, but for the overall community
18+
19+
Examples of unacceptable behavior include:
20+
21+
* The use of sexualized language or imagery, and sexual attention or advances of any kind
22+
* Trolling, insulting or derogatory comments, and personal or political attacks
23+
* Public or private harassment
24+
* Publishing others' private information, such as a physical or email address, without their explicit permission
25+
* Other conduct which could reasonably be considered inappropriate in a professional setting
26+
27+
## Enforcement Responsibilities
28+
29+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
32+
33+
## Scope
34+
35+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
36+
37+
## Enforcement
38+
39+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at **[email protected]**. All complaints will be reviewed and investigated promptly and fairly.
40+
41+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
42+
43+
## Enforcement Guidelines
44+
45+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
46+
47+
### 1. Correction
48+
49+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
50+
51+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
52+
53+
### 2. Warning
54+
55+
**Community Impact**: A violation through a single incident or series of actions.
56+
57+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interaction in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
58+
59+
### 3. Temporary Ban
60+
61+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
62+
63+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
64+
65+
### 4. Permanent Ban
66+
67+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
68+
69+
**Consequence**: A permanent ban from any sort of public interaction within the community.
70+
71+
## Attribution
72+
73+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
74+
75+
[homepage]: https://www.contributor-covenant.org
76+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2025 Andrew D. France
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# cl-win32-errors
2+
3+
A Common Lisp library for translating cryptic Windows API error codes into human-readable information. When working with CFFI, Windows functions often return numeric error codes. This library provides a simple interface to convert these codes into their symbolic names, hexadecimal values, and descriptive strings, complete with a condition system for error handling.
4+
5+
This project is the logical companion to [cl-win32-types](https://github.com/ItsMeForLua/cl-win32-types).
6+
7+
## Features
8+
9+
- **Error Mapping:** Translates over 2,300 system error codes across numerous categories, including core system, networking, RPC, security, Active Directory, DNS, and more.
10+
11+
- **Extensible:** The library is structured to make adding new error code definitions simple.
12+
13+
- **Condition System:** Provides a `win32-error` condition for idiomatic Lisp error handling.
14+
15+
- **User-Friendly API:** Simple functions to get error details or formatted strings.
16+
17+
- **ASDF System:** Ready for straightforward use via Quicklisp. The library and its tests are defined as separate systems.
18+
19+
20+
## Installation (for Users)
21+
22+
Once available in a Quicklisp distribution, you can load the library with:
23+
24+
``` lisp
25+
(ql:quickload :cl-win32-errors)
26+
```
27+
28+
## Developer Setup (for Contributors)
29+
30+
This project uses [Qlot](https://github.com/fukamachi/qlot "null") to manage and lock dependency versions for reproducible builds.
31+
32+
1. **Install Qlot** (one-time setup):
33+
34+
``` powershell
35+
ros install qlot
36+
```
37+
38+
2. Install Project Dependencies:
39+
40+
This command reads the qfile and installs the exact versions of all dependencies into a local .qlot/ directory.
41+
42+
``` powershell
43+
# Make sure you are in the project's root directory
44+
qlot install
45+
```
46+
47+
3. Start a REPL:
48+
49+
To work on the project, start your REPL using qlot exec. This ensures your Lisp session uses the project's local dependencies.
50+
51+
``` powershell
52+
qlot exec ros run
53+
```
54+
55+
56+
## Quick Start / Usage Example
57+
58+
Here is the most common use case for the library. All functions are exported from the `cl-win32-errors` package.
59+
60+
``` lisp
61+
;; Load the library
62+
(ql:quickload :cl-win32-errors)
63+
64+
;; Look up an error code
65+
(cl-win32-errors:get-error-details 2)
66+
;; => (:CODE 2 :HEX "0x2" :SYMBOL :ERROR_FILE_NOT_FOUND
67+
;; :DESCRIPTION "The system cannot find the file specified.")
68+
69+
;; Get a formatted string directly
70+
(cl-win32-errors:format-error-message 5 :verbosity :verbose)
71+
;; => "Win32 Error 5 (0x5/ERROR_ACCESS_DENIED): Access is denied."
72+
```
73+
74+
## API Reference
75+
76+
### `get-error-details` (error-code)
77+
78+
Looks up a numeric Win32 error code and returns a property list (plist) of its details.
79+
80+
**Parameters:**
81+
82+
- `error-code`: An integer representing the Windows error code.
83+
84+
**Returns:** A plist with the keys `:code`, `:hex`, `:symbol`, and `:description`, or `NIL` if the code is not found.
85+
86+
**Example:**
87+
88+
``` lisp
89+
(get-error-details 5)
90+
;; => (:CODE 5 :HEX "0x5" :SYMBOL :ERROR_ACCESS_DENIED :DESCRIPTION "Access is denied.")
91+
```
92+
93+
### `format-error-message` (error-code &key (verbosity :default))
94+
95+
Formats a Win32 error code into a human-readable string.
96+
97+
**Parameters:**
98+
99+
- `error-code`: An integer representing the Windows error code.
100+
101+
- `:verbosity`: A keyword, either `:default` or `:verbose`. The `:verbose` option includes the hex code and symbolic name.
102+
103+
104+
**Returns:** A formatted string.
105+
106+
**Example:**
107+
108+
``` lisp
109+
(format-error-message 87 :verbosity :verbose)
110+
;; => "Win32 Error 87 (0x57/ERROR_INVALID_PARAMETER): The parameter is incorrect."
111+
```
112+
113+
## Condition System
114+
115+
The library provides a `win32-error` condition for idiomatic error handling. You can signal it after a failed API call and use the provided accessors to inspect its details within a `handler-case`.
116+
117+
**Condition Accessors:**
118+
119+
- `win32-error-code` (condition): Returns the numeric error code.
120+
121+
- `win32-error-symbol` (condition): Returns the keyword symbol for the error.
122+
123+
- `win32-error-description` (condition): Returns the descriptive string for the error.
124+
125+
126+
**Example of handling an error:**
127+
128+
``` lisp
129+
(handler-case
130+
;; For example, signal an error after a failed API call
131+
(error 'cl-win32-errors:win32-error :code 87)
132+
(cl-win32-errors:win32-error (e)
133+
(format t "Caught a Win32 Error!~%")
134+
(format t " Code: ~A~%" (cl-win32-errors:win32-error-code e))
135+
(format t " Symbol: ~A~%" (cl-win32-errors:win32-error-symbol e))
136+
(format t " Description: ~A~%" (cl-win32-errors:win32-error-description e))))
137+
```
138+
139+
## Running Tests
140+
141+
To run the test suite from the command line, use `qlot exec`:
142+
143+
``` powershell
144+
qlot exec ros run --eval "(asdf:test-system :cl-win32-errors/tests)" --quit
145+
```
146+
147+
Alternatively, from within a REPL started with `qlot exec ros run`:
148+
149+
``` lisp
150+
(asdf:test-system :cl-win32-errors/tests)
151+
```
152+
153+
## Contributing
154+
155+
Bug reports and pull requests are welcome on GitHub. Please ensure the test suite passes before submitting a pull request.
156+
157+
## License
158+
159+
This project is licensed under the MIT License.

cl-win32-errors.asd

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
;;;; cl-win32-errors.asd
2+
3+
(defsystem #:cl-win32-errors
4+
:description "A library for translating Windows API error codes."
5+
:author "Your Name <[email protected]>"
6+
:license "MIT"
7+
:version "1.3.0"
8+
:depends-on ()
9+
:components ((:file "package")
10+
(:file "cl-win32-errors" :depends-on ("package"))
11+
;; Load all the error code files from the src/ directory.
12+
(:module "src"
13+
:depends-on ("cl-win32-errors")
14+
:components ((:file "core")
15+
(:file "network")
16+
(:file "rpc")
17+
(:file "security")
18+
(:file "extended")
19+
(:file "cluster")
20+
(:file "transactional")
21+
(:file "ds")
22+
(:file "dns")
23+
(:file "winsock")))))
24+
25+
(defsystem #:cl-win32-errors/tests
26+
:description "Test suite for cl-win32-errors."
27+
:author "Your Name <[email protected]>"
28+
:license "MIT"
29+
:depends-on (:cl-win32-errors
30+
:fiveam)
31+
:components ((:module "tests"
32+
:components ((:file "main"))))
33+
:perform (test-op (op c)
34+
(uiop:symbol-call :fiveam '#:run!
35+
(uiop:find-symbol* '#:cl-win32-errors-suite
36+
'#:cl-win32-errors/tests))))

0 commit comments

Comments
 (0)