mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:57:45 +00:00
LibPDF: Propagate errors in Parser and Document
This commit is contained in:
parent
7e1c823725
commit
73cf8205b4
16 changed files with 472 additions and 420 deletions
48
Userland/Libraries/LibPDF/Error.h
Normal file
48
Userland/Libraries/LibPDF/Error.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Matthew Olsson <mattco@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
|
||||
namespace PDF {
|
||||
|
||||
class Error {
|
||||
public:
|
||||
enum class Type {
|
||||
Parse,
|
||||
Internal,
|
||||
MalformedPDF,
|
||||
};
|
||||
|
||||
Error(Type type, String const& message)
|
||||
: m_type(type)
|
||||
{
|
||||
switch (type) {
|
||||
case Type::Parse:
|
||||
m_message = String::formatted("Failed to parse PDF file: {}", message);
|
||||
break;
|
||||
case Type::Internal:
|
||||
m_message = String::formatted("Internal error while processing PDF file: {}", message);
|
||||
break;
|
||||
case Type::MalformedPDF:
|
||||
m_message = String::formatted("Malformed PDF file: {}", message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Type type() const { return m_type; }
|
||||
String const& message() const { return m_message; }
|
||||
|
||||
private:
|
||||
Type m_type;
|
||||
String m_message;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using PDFErrorOr = ErrorOr<T, Error>;
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue