Skip to content
PT

Static copy

Copied from docs/guides/errors-null-void.md in https://github.com/poppy-team/ori-lang (MIT). Pinned to revision 42e1817227fbc96e8e4a4a85fac78b3fec0a0e0f, blob f729d2e9d568f384f5e0c5d5e20ff1bb4ef8b532. The source repository remains canonical; this copy is refreshed through a sync pull request, not live.

Errors, optional, void — mental model ​

Pedagogical guide (surface S3 + inference B / workspace 0.3.8-dev). Portuguese: errors-null-void.pt-BR.md
Normative: 09-errors, 04-types

Four concepts ​

ConceptRoleWhen
voidNo useful returnSide-effect functions
optional[T]Value may be absentLookup, EOF — absence is not failure
result[T, E]Success or failure with reasonI/O, validation
checkRuntime preconditionInvariants

Ori has no null. Use none or err(...).

void ​

ori
module app.main

import ori.io as io

greet() -> void
    io.println("hello")
end

main()
    greet()
end

optional[T] ​

ori
module app.main

find_user(id: int) -> optional[string]
    if id == 0
        return none
    end
    return some("alice")
end

main()
    match find_user(1)
        case some(name):
            -- use name
        case none:
    end
end
  • Unpack with if some(x) = expr or match.
  • try on optional propagates none.
  • Postfix ? was removed in S3.

result[T, E] ​

ori
module app.main

import ori.fs as fs

read_config(path: string) -> result[string, string]
    return fs.read_text(path)
end
  • Build with ok(value) / err(reason) (not success / error).
  • Handle with match or try expr.

check ​

ori
divide(a: int, b: int) -> int
    check b != 0, "division by zero"
    return a / b
end

Fails the process on broken contracts; it is not a result.

Quick map ​

SituationUse
Print only-> void
“Not found”, not an erroroptional[T]
Failure with messageresult[T, string]
Must always be truecheck
bash
ori explain name.undefined
ori doctor

Catalog: 13-error-catalog.md.