Skip to main content

Common Runtime Errors Reference

Error snippetCauseHow to fix
attempt to perform arithmetic on aTried arithmetic (+, -, *, /) on a non-numberValidate operands are numbers before arithmetic
attempt to compareTried comparison (>, <, >=, <=) on invalid valuesValidate both operands are comparable before comparison
attempt to concatenate aTried concatenating a non-string with ..Ensure both sides are strings before concatenation
attempt to call aTried to call a value that is not a functionEnsure the value is a function before calling
attempt to index aTried to index (subscript) a non-table valueEnsure the variable is a table before indexing
attempt to yield across a C-call boundaryTried to yield in a context that cannot yieldWhen using require, ensure the required module returns without calling yielding functions (marked with exclamation in this handbook). Also avoid using yielding functions in callbacks with C bridges.
invalid order function for sortingInvalid sort comparator; comparison logic is inconsistentUse a strict order function; it must not be simultaneously a>b and a<b for any pair
bad argument #1 to 'xxx' (number expected, got nil)Argument #1 to function 'xxx' is invalid; number expected but got nilPass a valid argument of the expected type
bad argument #2 to 'xxx' (number has no integer representation)Argument #2 cannot be represented as an integerPass a valid argument
bad argument #3 to 'xxx'Argument #3 is invalidPass a valid argument
  • Workaround for "attempt to yield across a C-call boundary" when using require:
      1. Add return function() to the first line of the required module
      1. Add end at the last line of the module
      1. Add an extra pair of parentheses when requiring: change require('A') to require('A')()