Skip to content

Commit b2b5da6

Browse files
authored
fix(core): log command files that fail to load (#62251)
1 parent a1dfa56 commit b2b5da6

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

‎packages/core/src/config/plugin/command.ts‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Entry } from "@opencode/schema/config"
55
import { ConfigCommand } from "@opencode/schema/config/command"
66
import { AppProcess } from "@opencode/util/process"
77
import path from "path"
8-
import { Effect, Option, Schema } from "effect"
8+
import { Effect, Result, SchemaIssue, SchemaParser } from "effect"
99
import { ChildProcess } from "effect/process"
1010
import { Agent } from "../../agent.js"
1111
import { Config } from "../../config.js"
@@ -17,7 +17,8 @@ import { FSUtil } from "@opencode/util/fs-util"
1717
import { ConfigMarkdown } from "../markdown.js"
1818
import { ConfigEntryObserver } from "./entry-observer.js"
1919

20-
const decodeCommand = Schema.decodeUnknownOption(ConfigCommand.Info)
20+
const decodeCommand = SchemaParser.decodeUnknownResult(ConfigCommand.Info)
21+
const formatIssue = SchemaIssue.makeFormatterDefault()
2122

2223
export const Plugin = define({
2324
id: "opencode.config.command",
@@ -125,7 +126,7 @@ function loadDirectory(fs: FSUtil.Interface, directory: string) {
125126
.pipe(Effect.orElseSucceed(() => [] as string[]))
126127
return yield* Effect.forEach(files.toSorted(), (filepath) =>
127128
fs.readFileStringSafe(filepath).pipe(
128-
Effect.map((content) => (content === undefined ? undefined : decode(directory, filepath, content))),
129+
Effect.flatMap((content) => (content === undefined ? Effect.undefined : decode(directory, filepath, content))),
129130
Effect.orElseSucceed(() => undefined),
130131
),
131132
).pipe(
@@ -136,20 +137,30 @@ function loadDirectory(fs: FSUtil.Interface, directory: string) {
136137
})
137138
}
138139

139-
function decode(directory: string, filepath: string, content: string) {
140+
const decode = Effect.fnUntraced(function* (directory: string, filepath: string, content: string) {
140141
const markdown = ConfigMarkdown.parseOption(content)
141-
if (!markdown) return
142-
const info = Option.getOrUndefined(decodeCommand({ ...markdown.data, template: markdown.content.trim() }))
143-
if (!info) return
142+
if (!markdown) {
143+
yield* Effect.logWarning("command file skipped", { filepath, reason: "markdown" })
144+
return
145+
}
146+
const info = decodeCommand({ ...markdown.data, template: markdown.content.trim() })
147+
if (Result.isFailure(info)) {
148+
yield* Effect.logWarning("command file skipped", {
149+
filepath,
150+
reason: "frontmatter",
151+
issue: formatIssue(info.failure),
152+
})
153+
return
154+
}
144155
return {
145156
name: path
146157
.relative(directory, filepath)
147158
.replaceAll("\\", "/")
148159
.replace(/^(command|commands)\//, "")
149160
.replace(/\.md$/, ""),
150-
info,
161+
info: info.success,
151162
}
152-
}
163+
})
153164

154165
function evaluateTemplate(
155166
template: string,

0 commit comments

Comments
 (0)