OpenCores
URL https://opencores.org/ocsvn/soc_maker/soc_maker/trunk

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [err.rb] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 feddischso
###############################################################
2
#
3
#  File:      err.rb
4
#
5
#  Author:    Christian Hättich
6
#
7
#  Project:   System-On-Chip Maker
8
#
9
#  Target:    Linux / Windows / Mac
10
#
11
#  Language:  ruby
12
#
13
#
14
###############################################################
15
#
16
#
17
#   Copyright (C) 2014  Christian Hättich  - feddischson [ at ] opencores.org
18
#
19
#   This program is free software: you can redistribute it and/or modify
20
#   it under the terms of the GNU General Public License as published by
21
#   the Free Software Foundation, either version 3 of the License, or
22
#   (at your option) any later version.
23
#
24
#   This program is distributed in the hope that it will be useful,
25
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
26
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
#   GNU General Public License for more details.
28
#
29
#   You should have received a copy of the GNU General Public License
30
#   along with this program.  If not, see .
31
#
32
#
33
###############################################################
34
#
35
#   Description:
36
#     Error definitions and functions, which are used via mixins.
37
#
38
#
39
###############################################################
40
 
41
 
42
module SOCMaker
43
 
44
  #
45
  # This sub-module contains some error-functionallity,
46
  # which is used in different classes via mixins.
47
  #
48
  # serr_if  means  raise Structure ERRor IF ...
49
  # verr_if  means  raise Value ERRor IF ...
50
  # lerr_if  means  raise Library ERRor IF ...
51
  # perr_if  mean   raise Processing ERRor IF
52
  module ERR
53
    class YAMLParseError < RuntimeError
54
    end
55
 
56
    class StructureError < RuntimeError
57
      attr :name
58
      attr :field
59
      def initialize( name, field, message )
60
        super message
61
        @name   = name
62
        @field  = field
63
       # p message
64
        SOCMaker::logger.error( "StructureError raised: " + message + " (#{name},#{field})" )
65
      end
66
      def to_s
67
        "->#{@name}:#{@field}"
68
      end
69
    end
70
 
71
    class LibError < RuntimeError
72
      attr :name
73
      def initialize( requested, message )
74
        super message
75
        @name = requested
76
        SOCMaker::logger.error( "LibError raised: " + message + " (#{requested})" )
77
      end
78
      def to_s
79
        "->#{@name}"
80
      end
81
    end
82
 
83
    class ProcessingError < RuntimeError
84
      def initialize( message )
85
        super message
86
        SOCMaker::logger.error( "ProcessingError raised: " + message )
87
      end
88
    end
89
 
90
    class ValueError < RuntimeError
91
      attr :name
92
      attr :field
93
      def initialize( name, field, message )
94
        super message
95
        @name = name
96
        @field = field
97
        SOCMaker::logger.error( "ValueError raised: " + message + " (#{name},#{field})" )
98
      end
99
      def to_s
100
        "->#{@name}:#{@field}"
101
      end
102
    end
103
 
104
 
105
 
106
    def serr_if( res, msg, o={} )
107
      o = { instance: '??', field: '??' }.merge( o )
108
      if !!( res )
109
        raise  StructureError.new( o[:instance], o[:field], msg )
110
      end
111
    end
112
 
113
    def verr_if( res, msg, o={})
114
      o = { instance: '??', field: '??' }.merge( o )
115
      if !!( res )
116
        raise ValueError.new( o[:instance], o[:field], msg )
117
      end
118
    end
119
 
120
    def lerr_if( res, msg, o={})
121
      o = { requested: '??' }.merge( o )
122
      if !!( res )
123
        raise LibError.new( o[:requested], msg )
124
      end
125
    end
126
 
127
    def perr_if( res, msg )
128
      if !!( res )
129
        raise ProcessingError.new( msg )
130
      end
131
    end
132
 
133
  end # module ERR
134
 
135
end # module SOCMaker

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.