1 //===- BinaryStreamError.cpp - Error extensions for streams -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Support/BinaryStreamError.h"
11 #include "llvm/Support/ErrorHandling.h"
15 char BinaryStreamError::ID
= 0;
17 BinaryStreamError::BinaryStreamError(stream_error_code C
)
18 : BinaryStreamError(C
, "") {}
20 BinaryStreamError::BinaryStreamError(StringRef Context
)
21 : BinaryStreamError(stream_error_code::unspecified
, Context
) {}
23 BinaryStreamError::BinaryStreamError(stream_error_code C
, StringRef Context
)
25 ErrMsg
= "Stream Error: ";
27 case stream_error_code::unspecified
:
28 ErrMsg
+= "An unspecified error has occurred.";
30 case stream_error_code::stream_too_short
:
31 ErrMsg
+= "The stream is too short to perform the requested operation.";
33 case stream_error_code::invalid_array_size
:
34 ErrMsg
+= "The buffer size is not a multiple of the array element size.";
36 case stream_error_code::invalid_offset
:
37 ErrMsg
+= "The specified offset is invalid for the current stream.";
39 case stream_error_code::filesystem_error
:
40 ErrMsg
+= "An I/O error occurred on the file system.";
44 if (!Context
.empty()) {
50 void BinaryStreamError::log(raw_ostream
&OS
) const { OS
<< ErrMsg
; }
52 StringRef
BinaryStreamError::getErrorMessage() const { return ErrMsg
; }
54 std::error_code
BinaryStreamError::convertToErrorCode() const {
55 return inconvertibleErrorCode();