Skip to content

Improve reporting of "fn is not a function" error#1317

Merged
josephjclark merged 3 commits intomainfrom
not-a-function
Mar 18, 2026
Merged

Improve reporting of "fn is not a function" error#1317
josephjclark merged 3 commits intomainfrom
not-a-function

Conversation

@josephjclark
Copy link
Collaborator

@josephjclark josephjclark commented Mar 18, 2026

Short Description

This PR reports a better error for the extremely frustrating "fn is not a function" error that creeps up when running a job like:

console.log('hi')

Fixes #811

Implementation Details

The problem occurs when the operations array that gets passed to the core execute reducer includes a non-function value.

When doing console.log() at the top level, we compile like this:

export default [console.log()]

Obviously console.log returns undefined, so this may as well be:

export default [undefined]

Which is an error in the runtime.

The validation catches this case and (hopefully!) returns a clearer error message - although of course this is a hard thing to explain, and it's hard to generate an error position at this point, so I have to be a bit vague.

QA Notes

Output in CLI:


[CLI] ♦ Versions:
         ▸ node.js                    22.12.0
         ▸ cli                        1.30.3
         ▸ @openfn/language-common    latest
[CLI] ♦ Imported 8 env vars from .env file
[CLI] ✔ Installing packages...
[CLI] ✔ Installation complete in 779ms
[CLI] ✔ Compiled all expressions in workflow
[JOB] ℹ hello
[R/T] ✘ job-1 aborted with error (1ms)

[R/T] ✘ CRITICAL ERROR! Aborting execution
[R/T] ✘ InvalidOperationError: Invalid operation at statement 0
[R/T] ✘ Ensure all top-level function or method calls are wrapped in an operation, like fn()

[CLI] ♦ Workflow failed in 837ms.
 ELIFECYCLE  Command failed with exit code 1.

Output in Worker:

image

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

@github-project-automation github-project-automation bot moved this to New Issues in Core Mar 18, 2026
@josephjclark josephjclark merged commit fc0b7ae into main Mar 18, 2026
6 checks passed
@github-project-automation github-project-automation bot moved this from New Issues to Done in Core Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Bad "fn is not a function" error when methods are in the code

2 participants