Fixing and explaining errors
Read an error code with actus explain, let actus fix apply the safe fixes, see the fixes that need your decision, and get the same data as JSON.
An error from the compiler has a code, such as E1005. Two commands help you
with it. actus explain tells you what the code means. actus fix applies the
fixes that the compiler is sure about. This page uses both.
Explain an error
A code tells you what kind of mistake it is. The same code always means the same thing. When a program uses a value after it was handed over, the error is:
main handed data to finish with dat, so it no longer owns it. The
last line uses it again. To read more, give the code to actus explain:
The output goes on with an example program that triggers the code and a
fix. The text above is shortened here. The catalog is part of the actus
program, so the command works without a network and always matches the
compiler that you have installed.
A code that does not exist gives an error and the exit status 2:
With --format json the entry is one JSON document. It has the fields
schema_version, command, code, title and markdown, where markdown
is the text unchanged. A program or an editor can read it.
Apply the safe fixes
Some errors have a fix that the compiler knows exactly. Here a verb is called with a dot, as the receiver's name and then the verb. Actus has one form for a call, and the error says which:
actus fix checks the project the way actus check does, applies the fixes
that are safe, and checks again. A safe fix cannot change what the
program means. It repeats this in rounds until no safe fix is left. Add
--dry-run first to see what it would do. Nothing is written:
The compiler found the role from the declaration, ins self: Counter, and wrote
it in the call. The program lends counter to bump, as the verb declares.
It needs two rounds because the compiler reports one error of this kind per
check. Run actus fix without --dry-run to write the change:
The program now is:
What actus fix writes:
- It writes only the
.actfiles of your project. It never writesActus.tomlorActus.lock, and it never writes the standard library or a dependency. A safe fix in such a file is listed and left alone. - It writes the edits of the fixes and nothing else. It does not format. Run
actus fmtafterwards if you want that. - Each file is replaced in one step, so a failure never leaves a file half written.
- Every fix is applied whole or not at all. A fix may change several places.
- It takes the same arguments as
check: a file, and--strict.
The exit status is 0 when no error is left after the fixes, 1 when one is left, and 2 for a wrong use of the command.
Fixes that need your decision
Not every fix is safe. A review fix changes what the program does, so
actus fix lists it and does not apply it. Here a call returns an Option and
throws it away:
The status is 1, because the error is still there. The fix would write
drop(first_even(a: abs two));, which says that you do not care about the
outcome. Only you can say that. Maybe you want to look at the value with
case instead, as in Errors: Result and Option. Make the
choice and edit the file yourself.
The same data as JSON
actus check --format json and actus fix --format json print one JSON
document and nothing else. Every error has its code, its message, its start and
end in the file, and a list of fixes. Each fix has a title, its edits and an
applicability that is safe or review. An editor shows the same fixes as
quick fixes. A script should apply only the safe ones on its own, and show a
review fix to a person first. Programs that read this output are described in
Using Actus with AI assistants.
What you learned
- An error code means the same thing every time.
actus explain E####prints what it means, an example and the fix, without a network. actus fixapplies thesafefixes of the project in rounds. Use--dry-runto read the changes first.- A
reviewfix is listed and never applied. You decide. --format jsongives the errors and fixes as data for editors and scripts.
Next: Editor support.