66 openOracleEpmSourceFile ,
77 storeOracleEpmDownload ,
88} from '@/lib/internal/oracle-epm/files.server'
9- import { pollOracleEpmJob } from '@/lib/internal/oracle-epm/jobs'
9+ import { type OracleEpmPollClassification , pollOracleEpmJob } from '@/lib/internal/oracle-epm/jobs'
1010import {
1111 PLANNING_DOWNLOAD_BYTES ,
1212 PLANNING_INPUT_FILE_BYTES ,
@@ -39,7 +39,9 @@ function findLink(status: InteropStatus, rel: string) {
3939 return links [ 0 ]
4040}
4141
42- function interopClassification ( status : InteropStatus ) {
42+ function interopClassification (
43+ status : InteropStatus
44+ ) : OracleEpmPollClassification < InteropStatus , InteropStatus > {
4345 if ( status . status === - 1 ) return { state : 'pending' } as const
4446 if ( status . status === 0 ) return { state : 'success' , result : status } as const
4547 return { state : 'failure' , error : status } as const
@@ -185,11 +187,15 @@ export async function downloadPlanningFile(
185187 }
186188 const maxWaitMs = ( input . maxWaitSeconds ?? 300 ) * 1000
187189 const deadlineAt = new Date (
188- Math . min ( Date . now ( ) + maxWaitMs , getExecutionDeadlineAt ( context . signal ) ?. getTime ( ) ?? Infinity )
190+ Math . min (
191+ Date . now ( ) + maxWaitMs ,
192+ getExecutionDeadlineAt ( context . signal ) ?. getTime ( ) ?? Number . POSITIVE_INFINITY
193+ )
189194 )
190195 let temporaryJobId : string | undefined
191196 let body : ReadableStream < Uint8Array > | undefined
192- let operationFailed = true
197+ let file : UserFile
198+ let cleanupFailed = false
193199 try {
194200 const initiation = parsePlanningResponse (
195201 interopStatusSchema ,
@@ -236,7 +242,7 @@ export async function downloadPlanningFile(
236242 if ( response . contentType ?. split ( ';' ) [ 0 ] . trim ( ) . toLowerCase ( ) === 'application/json' ) {
237243 throw new PlanningInputError ( 'Oracle returned an error instead of downloadable file content' )
238244 }
239- const file = await storeOracleEpmDownload ( {
245+ file = await storeOracleEpmDownload ( {
240246 body,
241247 fileName : input . fileName ,
242248 contentType : response . contentType ,
@@ -245,8 +251,6 @@ export async function downloadPlanningFile(
245251 maxBytes : PLANNING_DOWNLOAD_BYTES ,
246252 signal : context . signal ,
247253 } )
248- operationFailed = false
249- return file
250254 } catch ( error ) {
251255 if ( error instanceof PayloadSizeLimitError ) {
252256 throw new PlanningInputError (
@@ -269,11 +273,12 @@ export async function downloadPlanningFile(
269273 } catch {
270274 /** Preserve an earlier failure, and never include tenant identifiers or response bodies in logs. */
271275 logger . warn ( 'Oracle temporary download cleanup failed' )
272- if ( ! operationFailed )
273- throw new PlanningInputError (
274- 'File was stored, but Oracle temporary download cleanup failed'
275- )
276+ cleanupFailed = true
276277 }
277278 }
278279 }
280+ if ( cleanupFailed ) {
281+ throw new PlanningInputError ( 'File was stored, but Oracle temporary download cleanup failed' )
282+ }
283+ return file
279284}
0 commit comments