aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/vespa/document/base/exceptions.h
blob: 6b85c56e85ab79d45b05e362bf5b495454ce2006 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <memory>
#include <vespa/vespalib/util/exceptions.h>
#include <cstdint>

namespace document {

class DataType;

/**
 * \class document::InvalidDataTypeException
 * \ingroup base
 *
 * \brief Exception used to report invalid datatype usage.
 */
class InvalidDataTypeException : public vespalib::IllegalStateException
{
public:
    InvalidDataTypeException(const DataType &actual,
                             const DataType &wanted,
                             const vespalib::string & location);
    ~InvalidDataTypeException() override;

    const DataType& getActualDataType() const { return _actual; }
    const DataType& getExpectedDataType() const { return _expected; }

    VESPA_DEFINE_EXCEPTION_SPINE(InvalidDataTypeException);

private:
    const DataType &_actual;
    const DataType &_expected;

};

/**
 * \class document::InvalidDataTypeConversionException
 * \ingroup base
 *
 * \brief Exception used to report invalid datatype convertion.
 */
class InvalidDataTypeConversionException
    : public vespalib::IllegalStateException
{
public:
    InvalidDataTypeConversionException(const DataType &actual,
                                       const DataType &wanted,
                                       const vespalib::string & location);
    ~InvalidDataTypeConversionException() override;

    const DataType& getActualDataType() const { return _actual; }
    const DataType& getExpectedDataType() const { return _expected; }

    VESPA_DEFINE_EXCEPTION_SPINE(InvalidDataTypeConversionException);

private:
    const DataType &_actual;
    const DataType &_expected;

};

/**
 * \class document::DocumentTypeNotFoundException
 * \ingroup base
 *
 * \brief Exception used when a document type is not found.
 */
class DocumentTypeNotFoundException : public vespalib::Exception
{
private:
    vespalib::string _type;

public:
    DocumentTypeNotFoundException(const vespalib::string & name,
                                  const vespalib::string& location);
    ~DocumentTypeNotFoundException() override;

    const vespalib::string& getDocumentTypeName() const { return _type; }

    VESPA_DEFINE_EXCEPTION_SPINE(DocumentTypeNotFoundException);
};

/**
 * \class document::DataTypeNotFoundException
 * \ingroup base
 *
 * \brief Exception used when a data type is not found.
 */
class DataTypeNotFoundException : public vespalib::Exception
{
public:
    DataTypeNotFoundException(int id, const vespalib::string& location);
    DataTypeNotFoundException(const vespalib::string& name, const vespalib::string& location);
    ~DataTypeNotFoundException() override;

    VESPA_DEFINE_EXCEPTION_SPINE(DataTypeNotFoundException);
};

/**
 * \class document::AnnotationTypeNotFoundException
 * \ingroup base
 *
 * \brief Exception used when an annotation type is not found.
 */
class AnnotationTypeNotFoundException : public vespalib::Exception
{
public:
    AnnotationTypeNotFoundException(int id, const vespalib::string& location);
    ~AnnotationTypeNotFoundException() override;

    VESPA_DEFINE_EXCEPTION_SPINE(AnnotationTypeNotFoundException);
};

/**
 * \class document::FieldNotFoundException
 * \ingroup base
 *
 * \brief Typically thrown when accessing non-existing fields in structured
 *        datatypes.
 */
class FieldNotFoundException : public vespalib::Exception
{
private:
    vespalib::string _fieldName;
    int32_t _fieldId;

public:
    FieldNotFoundException(const vespalib::string& fieldName,
                           const vespalib::string& location);
    FieldNotFoundException(int32_t fieldId,
                           int16_t serializationVersion,
                           const vespalib::string& location);
    ~FieldNotFoundException() override;

    const vespalib::string& getFieldName() const { return _fieldName; }
    int32_t getFieldId()              const { return _fieldId; };

    VESPA_DEFINE_EXCEPTION_SPINE(FieldNotFoundException);
};

VESPA_DEFINE_EXCEPTION(WrongTensorTypeException, vespalib::Exception);

}