@devp0nt/error0 1.0.0-next.52 → 1.0.0-next.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,10 +11,9 @@ export const stackMergePlugin = ({
11
11
  }
12
12
  return error
13
13
  .causes()
14
- .map((cause) => {
15
- return cause instanceof Error ? cause.stack : undefined
14
+ .flatMap((cause) => {
15
+ return cause instanceof Error && cause.stack && typeof cause.stack === 'string' ? cause.stack : []
16
16
  })
17
- .filter((value): value is string => typeof value === 'string')
18
17
  .join(delimiter)
19
18
  },
20
19
  })
@@ -11,7 +11,7 @@ describe('tagsPlugin', () => {
11
11
  const leaf = new AppError('leaf', { tags: ['api', 'retry'], cause: root })
12
12
  expect(leaf.tags).toEqual(['api', 'retry', 'db'])
13
13
  expectTypeOf(leaf.tags).toEqualTypeOf<string[] | undefined>()
14
- expectTypeOf(leaf.own('tags')).toEqualTypeOf<string[] | undefined>()
14
+ expectTypeOf(leaf.own?.tags).toEqualTypeOf<string[] | undefined>()
15
15
  expectTypeOf(leaf.flow('tags')).toEqualTypeOf<Array<string[] | undefined>>()
16
16
  })
17
17
 
@@ -66,8 +66,6 @@ describe('tagsPlugin', () => {
66
66
 
67
67
  // @ts-expect-error - unknown tag is not part of allow-list
68
68
  error.hasTag('custom')
69
- // @ts-expect-error - array checks require policy argument
70
- error.hasTag(['api', 'db'])
71
69
  // @ts-expect-error - unsupported policy
72
70
  error.hasTag(['api', 'db'], 'all')
73
71
  })
@@ -5,21 +5,21 @@ export const tagsPlugin = <TTag extends string>({
5
5
  tags,
6
6
  strict = true,
7
7
  }: { isPublic?: boolean; tags?: TTag[] | readonly TTag[]; strict?: boolean } = {}) => {
8
- function hasTag(error: Error0, tag: TTag): boolean
9
- function hasTag(error: Error0, tag: TTag[], policy: 'every' | 'some'): boolean
10
- function hasTag(error: Error0, tag: TTag | TTag[], policy?: 'every' | 'some'): boolean {
11
- const tags = (error as any).tags as string[] | undefined
12
- if (!tags) {
13
- return false
14
- }
15
- if (Array.isArray(tag)) {
16
- if (policy === 'every') {
17
- return tag.every((item) => tags.includes(item))
18
- }
19
- return tag.some((item) => tags.includes(item))
20
- }
21
- return tags.includes(tag)
22
- }
8
+ // function hasTag(error: Error0, tag: TTag): boolean
9
+ // function hasTag(error: Error0, tag: TTag[], policy: 'every' | 'some'): boolean
10
+ // function hasTag(error: Error0, tag: TTag | TTag[], policy?: 'every' | 'some'): boolean {
11
+ // const tags = (error as any).tags as string[] | undefined
12
+ // if (!tags) {
13
+ // return false
14
+ // }
15
+ // if (Array.isArray(tag)) {
16
+ // if (policy === 'every') {
17
+ // return tag.every((item) => tags.includes(item))
18
+ // }
19
+ // return tag.some((item) => tags.includes(item))
20
+ // }
21
+ // return tags.includes(tag)
22
+ // }
23
23
  const isTag = (value: unknown): value is TTag =>
24
24
  typeof value === 'string' && (!tags || !strict || tags.includes(value as TTag))
25
25
  return Error0.plugin()
@@ -47,5 +47,17 @@ export const tagsPlugin = <TTag extends string>({
47
47
  return value.filter((item) => isTag(item))
48
48
  },
49
49
  })
50
- .method('hasTag', hasTag)
50
+ .method('hasTag', (error, tag: TTag | TTag[], policy: 'every' | 'some' = 'every'): boolean => {
51
+ const tags = error.tags
52
+ if (!tags) {
53
+ return false
54
+ }
55
+ if (Array.isArray(tag)) {
56
+ if (policy === 'every') {
57
+ return tag.every((item) => tags.includes(item))
58
+ }
59
+ return tag.some((item) => tags.includes(item))
60
+ }
61
+ return tags.includes(tag)
62
+ })
51
63
  }