Skip to main content

Error code reference

Error CodeDescriptionExampleExplanation
M0001Parsing errors.let x = 5 + ;Syntax error - missing operand after the + operator.
M0003Module tried to import itself.import Self "self.mo"A module cannot import itself, creating a circular dependency.
M0009File not found for import.import Lib "wrong/path_to_file.mo"The specified file path in the import statement doesn't exist.
M0010Imported package was not defined.import { undefined_module } from "mo:package"The imported module doesn't exist in the specified package.
M0014Non-static expression in library or module.module { let x = Random.blob(); }Modules can only contain static definitions, not runtime expressions.
M0029Unbound type.func transform(x : UnknownType) { ... }The type UnknownType is referenced but hasn't been defined.
M0030Type field does not exist in type.type Person = { name : Text }; func getName(p : Person) : Nat { p.age }The field age doesn't exist in the Person type.
M0031Shared function has non-shared parameter type.public shared func process(obj : { var count : Nat }) { ... }Shared functions cannot have mutable types as parameters.
M0032Shared function has non-shared return type.public shared func getData() : { var data : [Nat] } { ... }Shared functions cannot return mutable types.
M0033Async has non-shared content type.async { var counter = 0 }Async blocks cannot contain mutable state.
M0036Invalid return type for shared query function.public shared query func getUsers() : async [User] { ... }Query functions cannot return async types.
M0038Misplaced await.func compute() { let x = await promise; }await can only be used in an async function or block.
M0045Wrong number of type arguments.func process<T>(x : Array<T, Nat>) { ... }Array type expects one type parameter, not two.
M0047Send capability required.actor { public func send() { IC.call(...); } }Functions calling IC management require explicit capability declarations.
M0050Literal does not have expected type.let x : Text = 42;Cannot assign a number literal to a variable of type Text.
M0055Cannot infer type of forward variable.func process() { x := 10; var x = 0; }Variable x is used before its declaration.
M0057Unbound variable.func calculate() { return result; }The variable result is used but hasn't been defined.
M0060Operator is not defined for operand types.let result = "text" - 5;The subtraction operator isn't defined for Text and Nat types.
M0064Misplaced '!' without enclosing do blockfunc test() { someFunction!(); }The ! operator must be used within a do block.
M0070Expected object type.let name = person.name; (where person is not an object)Trying to access a field on a non-object type.
M0072Field does not exist in type.type User = { id : Nat }; func getName(u : User) { u.name }The field name doesn't exist in the User type.
M0073Expected mutable assignment target.let x = 5; x := 10;Cannot reassign to an immutable variable declared with let.
M0082Expected iterable type.for (item in 42) { ... }The value 42 is not an iterable type for a for-loop.
M0088Expected async type.let result = await 42;Cannot await on a non-async value.
M0089Redundant ignore.ignore (5);The ignore is unnecessary for a value that doesn't need to be ignored.
M0090Actor reference must have an actor type .let a = actor { ... }; a.someMethod();The variable a must have an explicit actor type to call its methods.
M0096Expression can't produce expected type.func getValue() : Bool { return "true"; }String cannot be returned where a Bool is expected.
M0097Expected function type.let x = 5; x();Cannot call a non-function value.
M0098Cannot instantiate function type.type Func = (Nat) -> Nat; let f = Func();Function types cannot be instantiated directly.
M0112Tuple pattern cannot consume type.let (x, y) = { a = 1; b = 2 };Cannot destructure an object using tuple pattern.
M0116Variant pattern cannot consume type.switch (value) { case (#ok(x)) { ... } }; (where value is not a variant)Cannot match a non-variant value with variant patterns.
M0126Shared function cannot be private.actor { private shared func publicAPI() { ... } }Shared functions must be public in actors.
M0137A type or class was declared that explicitly or implicitly references an outer type parameter.class Container<T>() { class Inner() { var value : T = ... } }Inner classes cannot reference type parameters from outer classes.
M0139Inner actor classes are not supported.class Outer() { actor class Inner() { ... } }Actor classes cannot be nested inside other classes.
M0141Forbidden declaration in program.import Prim "mo:prim";Certain imports/declarations are not allowed in normal user code.
M0145Pattern does not cover value.switch (option) { case (null) { ... } }; (missing ?some case)Switch statement doesn't handle all possible values.
M0149An immutable record field (declared without var) was supplied where a mutable record field (specified with var), was expected.type Mutable = { var x : Nat }; func set(r : Mutable) { ... }; set({ x = 10 });Immutable record provided where mutable was expected.
M0150A mutable record field (declared with var) was supplied where an immutable record field (specified without var) was expected.type Immutable = { x : Nat }; let record : Immutable = { var x = 10 };Mutable field provided where immutable was expected.
M0151A object literal is missing some fields.type Person = { name : Text; age : Nat }; let p : Person = { name = "John" };The age field is missing from the object literal.
M0153An imported Candid file (.did) mentions types that cannot be represented in Motoko.import Types from "types.did"; (where types.did contains incompatible types)The imported Candid file contains types that don't map to Motoko types.
M0154Deprecation annotation.@deprecated("Use newFunction instead") func oldFunction() { ... }Using a deprecated function or feature that has been marked with @deprecated.
M0155Inferred type Nat for subtraction.let x = 5 - 10;Subtraction with natural numbers can underflow without type annotation.
M0156A parameterized type definition, or set of type definitions, is too complicated for Motoko to accept.type Complex<A,B,C,D,E,F> = ... (extremely nested recursive types)Type definition too complex for the compiler to process.
M0157A type definition, or set of type definitions, is ill-defined.type RecursiveType = RecursiveType;A type directly references itself without proper indirection.
M0158A public class was declared without providing it with a name.public class<T>() { ... }Public parameterized classes must be named explicitly.
M0194An identifier was defined without referencing it later.func process() { let unused = computeValue(); }The variable unused is defined but never used.
M0195A function that demands elevated (system) capabilities was called without manifestly passing the capability.func splitCycles() { let amount = ExperimentalCycles.balance() / 2; ExperimentalCycles.add(amount);}}System capability function called without proper capability passing.
M0197A function that requires (system) capabilities was called in a context that does not provide them.func invalidCycleAddition(): () { ExperimentalCycles.add(1000);}Calling a function requiring system capabilities from a context without them.
M0198A field identifier was specified in an object pattern without referencing this identifier later.func process(obj) { let { id } = obj; }The extracted id field is never used in the function body.