Issues with error handling and stack traces in a CLI tool using the Effect Typescript library can...

Hey! I am facing problems while writing a CLI tool. It has few services, including config. Config layer can fail for multiple reasons. When it does i am facing totally crazy, unreadable errors (stack trace is repeated 3 times maybe it's because multiple services require config and it's being initializaed multiple times?). What am I doing wrong? I want cause (missing env) to be clearly visible (I am working on CLI tool).

export const configLayer = Layer.effect(
  CliConfig,
  Effect.gen(function* () {
    const config = yield* loadRawConfigFromFile

    const decodedConfig: GlobalConfig = yield* Schema.decodeUnknownEither(configSchema, { onExcessProperty: 'error' })(
      config,
    )

    yield* Effect.logInfo('Config loaded')

    return yield* make(decodedConfig)
  }).pipe(Effect.withSpan('configLayer')),
) satisfies Layer.Layer<CliConfig, unknown>
image.png
Was this page helpful?