Error handling
InvalidInputError, content extraction errors, and what the SDK does not wrap.
edu-sdk validates options with Zod before calling the model. Bad options throw InvalidInputError, which extends EduSDKError.
File extraction failures throw UnsupportedContentError (unknown type) or ContentExtractionError (empty / unreadable file). Both also extend EduSDKError.
import {
createQuiz,
InvalidInputError,
UnsupportedContentError,
ContentExtractionError,
} from "edu-sdk";
try {
const quiz = await createQuiz({
model: "google/gemini-3.6-flash",
content,
count: 10,
});
} catch (error) {
if (error instanceof InvalidInputError) {
// Empty content, count of 0, invalid difficulty, numOfOptions < 2, ...
console.error(error.message);
} else if (
error instanceof UnsupportedContentError ||
error instanceof ContentExtractionError
) {
console.error(error.message);
} else {
throw error;
}
}Invalid input examples
- empty
content countof0or a non-integerdifficultyother than"easy" | "medium" | "hard"numOfOptionsless than2- duplicate types in
createLearningSetinclude
Study sessions
createStudySession() also throws InvalidInputError when:
durationMinutesis outside 5–240- block durations sum to a value more than ±5 minutes from
durationMinutes - a block’s
materialKeyreferences a material that was not allocated - the plan has no blocks
- every block is a
break - normalizing durations would make a block shorter than 1 minute
Content extraction errors
| Error | When |
|---|---|
UnsupportedContentError | Unknown MIME and no usable filename extension |
ContentExtractionError | Empty bytes, empty extracted text, or unscannable PDF |
What the SDK does not wrap
Model, network, rate-limit, and generation failures come from the AI SDK. They are not wrapped in EduSDKError. See Models & providers.