Skip to content

Commit

Permalink
fix: tag edge function signature errors as user errors (#209)
Browse files Browse the repository at this point in the history
* fix: tag edge function signature errors as user errors
  • Loading branch information
jackiewmacharia committed Nov 18, 2022
1 parent 887afbc commit 5d5a50f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions node/bundle_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ interface BundleErrorOptions {
format: string
}

const getCustomErrorInfo = (options: BundleErrorOptions) => ({
const getCustomErrorInfo = (options?: BundleErrorOptions) => ({
location: {
format: options.format,
format: options?.format,
runtime: 'deno',
},
type: 'functionsBundling',
Expand All @@ -13,7 +13,7 @@ const getCustomErrorInfo = (options: BundleErrorOptions) => ({
class BundleError extends Error {
customErrorInfo: ReturnType<typeof getCustomErrorInfo>

constructor(originalError: Error, options: BundleErrorOptions) {
constructor(originalError: Error, options?: BundleErrorOptions) {
super(originalError.message)

this.customErrorInfo = getCustomErrorInfo(options)
Expand All @@ -28,7 +28,7 @@ class BundleError extends Error {
/**
* BundleErrors are treated as user-error, so Netlify Team is not alerted about them.
*/
const wrapBundleError = (input: unknown, options: BundleErrorOptions) => {
const wrapBundleError = (input: unknown, options?: BundleErrorOptions) => {
if (input instanceof Error) {
return new BundleError(input, options)
}
Expand Down
7 changes: 5 additions & 2 deletions node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { pathToFileURL } from 'url'
import tmp from 'tmp-promise'

import { DenoBridge } from './bridge.js'
import { BundleError } from './bundle_error.js'
import { EdgeFunction } from './edge_function.js'
import { ImportMap } from './import_map.js'
import { Logger } from './logger.js'
Expand Down Expand Up @@ -123,8 +124,10 @@ const logConfigError = (func: EdgeFunction, exitCode: number, stderr: string, lo
break

case ConfigExitCode.InvalidDefaultExport:
throw new Error(
`Default export in '${func.path}' must be a function. More on the Edge Functions API at https://ntl.fyi/edge-api.`,
throw new BundleError(
new Error(
`Default export in '${func.path}' must be a function. More on the Edge Functions API at https://ntl.fyi/edge-api.`,
),
)

default:
Expand Down

0 comments on commit 5d5a50f

Please sign in to comment.