transloadit/uppy · error
res.sendStatus(500)
Error message
res.sendStatus(500)
What it means
The search controller returns HTTP 500 when companion.buildURL is missing or the 'q' query parameter is not a string. This is a server-side invariant failure: the URL builder was not injected or the query string was malformed/absent.
Source
Thrown at packages/@uppy/companion/src/server/controllers/search.ts:19
import type { NextFunction, Request, Response } from 'express'
import { respondWithError } from '../provider/error.js'
export default async function search(
req: Request,
res: Response,
next: NextFunction,
): Promise<void> {
const { query, companion } = req
const { providerUserSession, provider } = companion
if (!provider) {
res.sendStatus(400)
return
}
const buildURL = companion.buildURL
const q = query['q']
if (buildURL == null || typeof q !== 'string') {
res.sendStatus(500)
return
}
try {
const data = await provider.search({
companion: { buildURL },
providerUserSession,
query: { ...query, q },
})
res.json(data)
} catch (err) {
if (respondWithError(err, res)) return
next(err)
}
}
View on GitHub (pinned to 5d4dedd02a)
Solutions
- Ensure the request includes a single string q parameter (normally guarded by hasSearchQuery middleware — check routing order)
- Verify the provider search route uses the standard Companion router so req.companion.buildURL is attached
- If q is user-supplied, validate/normalize it to a string before calling the endpoint
Example fix
// before
fetch('/search/unsplash')
// after
fetch(`/search/unsplash?q=${encodeURIComponent(query)}`) Defensive patterns
Strategy: type-guard
Validate before calling
if (typeof q !== 'string' || q === '') throw new TypeError('q must be a non-empty string') Type guard
const isSearchQuery = (q: unknown): q is string => typeof q === 'string' && q.length > 0
Prevention
- Always use companion-client's provider.search() rather than raw fetch
- Normalize query params before building URLs
When it happens
Trigger: Calling the search endpoint without a q parameter, with q duplicated into an array (?q=a&q=b), or when Companion's internal buildURL helper is not set on req.companion (miswired middleware/routing).
Common situations: Client sends GET to /search/:provider without a search term; custom middleware setup bypassing Companion's standard initializers; query parsers producing arrays for repeated params.
Related errors
- File data is missing for file ${options.file.id}
- Missing S3 object key for completing multipart upload
- One of options `companionEndpoint`, `signRequest`, or `getCr
- [s3mini] fileType must be a string
- [s3mini] uploadId must be a non-empty string
AI-assisted analysis of transloadit/uppy@5d4dedd02a (2026-08-28).
Data as JSON: /api/errors/0ace2f995dc9410c.
Report an issue: GitHub.