#Error

#Error("message") before a declaration makes every call of it, or every use of a type or constant, a compile error with that message. The declaration itself compiles; only its use is refused, and the error points at the call. It lets a function that was removed, or that cannot work on this build, explain what to call instead rather than simply vanishing.

error-attribute = "#Error" "(" string-literal ")"
#Error("Connect was removed; call Open instead")
func Connect() -> int {
    return 0;
}

func Main() -> int {
    let k = Connect();
    return 0;
}
Src/Main.rux:7:13: error: Connect was removed; call Open instead

A declaration nobody uses produces nothing. The message must be a string literal, and as an attribute #Error needs no import.

Per-platform stubs

Combined with when, the attribute turns a missing implementation into a clear message at the call, instead of a missing name or a link failure:

import Core::{ #target };

when #target.os == .Windows {
    func OpenConsole() -> bool {
        return true;   // the real Windows implementation
    }
} else {
    #Error("OpenConsole is available on Windows only")
    func OpenConsole() -> bool {
        return false;
    }
}

Every other target still compiles the package; only a program that calls OpenConsole there is refused.

What it applies to

Like #Warn, #Error fires at calls of a function, a method, a constructor or an extern func, and at a function named as a value, let c = Connect;. On a struct, a constant, a type alias or an enum it fires at every use of the name, each use its own error: with #Error("Handle was removed; use File") on struct Handle, let h: Handle = …; is error: Handle was removed; use File. Uses inside the declaration's own fields and extend blocks are not reported.

The directive form

Written as a statement in a body or as a when arm, #Error("…") is a directive that stops the build wherever it is reached — see Build diagnostics.

See also