Skip to content

Commit

Permalink
feat: throw error on invalid service access
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Nov 21, 2024
1 parent 7d3a9fe commit 1221aae
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/reflect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ReflectService {
const lines = error.stack!.split('\n')
lines.splice(1, 1)
error.stack = lines.join('\n')
ctx.emit(ctx, 'internal/warning', error)
throw error
}

static handler: ProxyHandler<Context> = {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class Registry<C extends Context = Context> {
return this.plugin({ inject, apply: callback, name: callback.name })
}

plugin(plugin: Plugin<C>, config?: any) {
plugin(plugin: Plugin<C>, config?: any, outerError = new Error()) {
// check if it's a valid plugin
const key = this.resolve(plugin, true)
this.ctx.scope.assertActive()
Expand All @@ -199,7 +199,6 @@ class Registry<C extends Context = Context> {
this._internal.set(key!, runtime)
}

const outerError = new Error()
return new EffectScope(this.ctx, config, async (ctx, config) => {
const innerError = new Error()
try {
Expand Down
5 changes: 2 additions & 3 deletions packages/core/tests/invoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ describe('functional service', () => {
}

protected [Service.invoke](init?: Config) {
const caller = this.ctx
expect(caller).to.be.instanceof(Context)
expect(this.ctx).to.be.instanceof(Context)
let result = { ...this.config }
let intercept = caller[Context.intercept]
let intercept = this.ctx[Context.intercept]
while (intercept) {
Object.assign(result, intercept.foo)
intercept = Object.getPrototypeOf(intercept)
Expand Down

0 comments on commit 1221aae

Please sign in to comment.