• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / storage / 23952103731

03 Apr 2026 03:41PM UTC coverage: 80.549% (+0.04%) from 80.508%
23952103731

Pull #965

github

web-flow
Merge da8a838ab into 55b13d856
Pull Request #965: fix: report errors in orphan and test entity expansion

3140 of 4075 branches covered (77.06%)

Branch coverage included in aggregate %.

114 of 145 new or added lines in 5 files covered. (78.62%)

4 existing lines in 1 file now uncovered.

30038 of 37115 relevant lines covered (80.93%)

311.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.96
/src/scripts/orphan-client-stream.ts
1
import fs from 'fs'
1✔
2
import { mkdir } from 'fs/promises'
1✔
3
import path from 'path'
1✔
4
import { pipeline } from 'stream/promises'
1✔
5

1✔
6
export interface OrphanObject {
1✔
7
  event: 'data'
1✔
8
  type: 'dbOrphans' | 's3Orphans'
1✔
9
  value: {
1✔
10
    name: string
1✔
11
    version: string
1✔
12
    size: number
1✔
13
  }[]
1✔
14
}
1✔
15

1✔
16
export interface PingObject {
1✔
17
  event: 'ping'
1✔
18
}
1✔
19

1✔
20
export interface StreamedErrorPayload {
1✔
21
  statusCode: string
1✔
22
  code: string
1✔
23
  error: string
1✔
24
  message: string
1✔
25
}
1✔
26

1✔
27
export interface ErrorObject {
1✔
28
  event: 'error'
1✔
29
  error: StreamedErrorPayload
1✔
30
}
1✔
31

1✔
32
export type OrphanStreamEvent = OrphanObject | PingObject | ErrorObject
1✔
33

1✔
34
export function formatOrphanStreamError(error: StreamedErrorPayload) {
2✔
35
  return `[${error.code}] ${error.message}`
2✔
36
}
2✔
37

1✔
38
export async function writeStreamToJsonArray(
1✔
39
  stream: NodeJS.ReadableStream,
4✔
40
  filePath: string
4✔
41
): Promise<void> {
4✔
42
  await mkdir(path.dirname(filePath), { recursive: true })
4✔
43

4✔
44
  const localFile = fs.createWriteStream(filePath)
4✔
45
  let isFirstItem = true
4✔
46
  let receivedAnyData = false
4✔
47
  let streamedError: Error | undefined
4✔
48
  let deleteLimitReached = false
4✔
49

4✔
50
  const jsonArrayStream = (async function* () {
4✔
51
    yield '[\n'
4✔
52

4✔
53
    try {
4✔
54
      for await (const data of stream as AsyncIterable<OrphanStreamEvent>) {
4✔
55
        if (data.event === 'ping') {
4!
NEW
56
          console.log('Received ping event, ignoring')
×
NEW
57
          continue
×
NEW
58
        }
×
59

4✔
60
        if (data.event === 'error') {
4✔
61
          streamedError = new Error(formatOrphanStreamError(data.error))
1✔
62
          console.error('Server error:', formatOrphanStreamError(data.error))
1✔
63
          continue
1✔
64
        }
1✔
65

3✔
66
        if (data.value && Array.isArray(data.value)) {
4✔
67
          receivedAnyData = true
3✔
68
          console.log(`Processing ${data.value.length} objects`)
3✔
69

3✔
70
          for (const item of data.value) {
3✔
71
            if (!isFirstItem) {
3!
NEW
72
              yield ',\n'
×
73
            } else {
3✔
74
              isFirstItem = false
3✔
75
            }
3✔
76

3✔
77
            yield JSON.stringify({ ...item, orphanType: data.type }, null, 2)
3✔
78
          }
3✔
79
          continue
3✔
80
        }
3✔
NEW
81

×
NEW
82
        console.warn(
×
NEW
83
          'Received data with invalid format:',
×
NEW
84
          JSON.stringify(data).substring(0, 100) + '...'
×
NEW
85
        )
×
NEW
86
      }
×
87
    } catch (err) {
4✔
88
      if (err instanceof Error && err.message === 'DELETE_LIMIT_REACHED') {
1✔
89
        deleteLimitReached = true
1✔
90
      } else {
1!
NEW
91
        throw err
×
NEW
92
      }
×
93
    }
1✔
94

4✔
95
    yield '\n]'
4✔
96
  })()
4✔
97

4✔
98
  await pipeline(jsonArrayStream, localFile)
4✔
99

3✔
100
  if (streamedError) {
4✔
101
    throw streamedError
1✔
102
  }
1✔
103

2✔
104
  if (!receivedAnyData) {
4!
NEW
105
    console.warn(`No data was received! File might be empty: ${filePath}`)
×
NEW
106
    return
×
NEW
107
  }
×
108

2✔
109
  if (deleteLimitReached) {
4✔
110
    console.log(`Finished writing data to ${filePath}. Delete limit reached, data saved.`)
1✔
111
    return
1✔
112
  }
1✔
113

1✔
114
  console.log(`Finished writing data to ${filePath}. Data was received and saved.`)
1✔
115
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc