iflytek/astron-agent · error · Error

errorMessage (dynamic; error.message or fallback 'Failed to…

Error message

errorMessage (dynamic; error.message or fallback 'Failed to upload image')

What it means

uploadFile in utils.ts wraps its body in try/catch and rethrows a single Error whose message is error.message when the cause is an Error, otherwise the fallback 'Failed to upload image'. It preserves the underlying reason (network failure, presign failure, PUT rejection) but loses the original error type/stack.

Solutions

  1. Inspect error.message from the caught Error to identify whether presign or the PUT step failed
  2. Check object-storage (MinIO/S3) credentials, bucket existence, and CORS config
  3. Validate file size/type before calling uploadFile
  4. Preserve the original error (cause) or rethrow it instead of flattening to a string for easier debugging

Example fix

// before
} catch (error: unknown) {
  const errorMessage = error instanceof Error ? error.message : 'Failed to upload image';
  throw new Error(errorMessage);
}
// after
} catch (error: unknown) {
  if (error instanceof Error) throw error; // keep original stack
  throw new Error('Failed to upload image: ' + String(error));
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!(file instanceof File) || file.size === 0 || file.size > MAX_UPLOAD_SIZE) {
  throw new Error('Invalid or oversized file');
}

Type guard

function isUploadable(f: unknown): f is File {
  return f instanceof File && f.size > 0;
}

Try / catch

try {
  const res = await uploadFile(file, bucket);
} catch (e) {
  if (e instanceof Error) showToast(e.message);
  else showToast('Failed to upload image');
}

Prevention

When it happens

Trigger: Any failure inside uploadFile: fetch of presigned upload URL fails, MinIO/S3 PUT returns non-2xx, network offline, invalid bucket or file object passed in, or a thrown non-Error value (string rejection).

Common situations: Expired/misconfigured object-storage credentials causing presign or PUT 403; oversized image hitting a proxy limit; CORS blocking the PUT to the storage endpoint; transient network loss during upload.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/f6bc84c3ab6fa8a2. Report an issue: GitHub.

Appendix: source

Thrown at console/frontend/src/utils/utils.ts:454

          'Content-Type': file.type,
        },
      })
      .put(url, file, {
        headers: {
          'Content-Type': file.type,
        },
      });
    const fileUrl = url.split('?')[0];
    return {
      url: fileUrl,
      objectKey: responseObjectKey,
      fileName: file.name,
      bucket,
    };
  } catch (error: unknown) {
    const errorMessage =
      error instanceof Error ? error.message : 'Failed to upload image';
    throw new Error(errorMessage);
  }
}

/**
 * 文本中间字符替换为星号(脱敏)
 * @param text 原始文本(必填)
 * @param options 配置项(可选)
 * - prefixLen 前面保留的字符数,默认 1
 * - suffixLen 后面保留的字符数,默认 1
 * - starLen 星号长度,默认 2(文本较长时自动调整,避免星号过多)
 * @returns 脱敏后的文本
 */
export const maskMiddleText = (
  text: string,
  options: { prefixLen?: number; suffixLen?: number; starLen?: number } = {}
) => {
  // 处理边界:文本为空、null/undefined 或非字符串,直接返回空
  if (!text || typeof text !== 'string') return '';

View on GitHub (pinned to 5e758547a8)