From e1dfec175ac96f7396e375dde1f2380ecca06c87 Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Tue, 1 Dec 2015 14:31:41 +0100
Subject: [PATCH] add more helpful error messages. closes #6

---
 src/@report/addGraph.m     |  6 +++++-
 src/@report/addParagraph.m |  6 +++++-
 src/@report/addSection.m   |  4 +++-
 src/@report/addSeries.m    | 11 ++++++++++-
 src/@report/addTable.m     |  6 +++++-
 src/@report/addVspace.m    |  6 +++++-
 6 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/@report/addGraph.m b/src/@report/addGraph.m
index 9e0e691..1c703a3 100644
--- a/src/@report/addGraph.m
+++ b/src/@report/addGraph.m
@@ -12,7 +12,7 @@ function o = addGraph(o, varargin)
 % SPECIAL REQUIREMENTS
 %   none
 
-% Copyright (C) 2013-2014 Dynare Team
+% Copyright (C) 2013-2015 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -29,6 +29,10 @@ function o = addGraph(o, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+assert(length(o.pages) > 0, ...
+       '@report.addGraph: Before adding a graph, you must add a page and a section.');
+assert(length(o.pages{end}.sections) > 0, ...
+       '@report.addGraph: Before adding a graph, you must add a section.');
 o.pages{end}.sections{end} = ...
     o.pages{end}.sections{end}.addGraph(varargin{:});
 end
diff --git a/src/@report/addParagraph.m b/src/@report/addParagraph.m
index 4ec7209..56e605f 100644
--- a/src/@report/addParagraph.m
+++ b/src/@report/addParagraph.m
@@ -12,7 +12,7 @@ function o = addParagraph(o, varargin)
 % SPECIAL REQUIREMENTS
 %   none
 
-% Copyright (C) 2013-2014 Dynare Team
+% Copyright (C) 2013-2015 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -29,6 +29,10 @@ function o = addParagraph(o, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+assert(length(o.pages) > 0, ...
+       '@report.addParagraph: Before adding a paragraph, you must add a page and a section.');
+assert(length(o.pages{end}.sections) > 0, ...
+       '@report.addParagraph: Before adding a paragraph, you must add a section.');
 o.pages{end}.sections{end} = ...
     o.pages{end}.sections{end}.addParagraph(varargin{:});
 end
diff --git a/src/@report/addSection.m b/src/@report/addSection.m
index 3387b94..eec30fd 100644
--- a/src/@report/addSection.m
+++ b/src/@report/addSection.m
@@ -12,7 +12,7 @@ function o = addSection(o, varargin)
 % SPECIAL REQUIREMENTS
 %   none
 
-% Copyright (C) 2013-2014 Dynare Team
+% Copyright (C) 2013-2015 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -29,5 +29,7 @@ function o = addSection(o, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+assert(length(o.pages) > 0, ...
+       '@report.addSection: Before adding a section, you must add a page.');
 o.pages{end} = o.pages{end}.addSection(varargin{:});
 end
diff --git a/src/@report/addSeries.m b/src/@report/addSeries.m
index 459230b..28f9063 100644
--- a/src/@report/addSeries.m
+++ b/src/@report/addSeries.m
@@ -12,7 +12,7 @@ function o = addSeries(o, varargin)
 % SPECIAL REQUIREMENTS
 %   none
 
-% Copyright (C) 2013-2014 Dynare Team
+% Copyright (C) 2013-2015 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -29,6 +29,15 @@ function o = addSeries(o, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+assert(length(o.pages) > 0, ...
+       ['@report.addSeries: Before adding a series, you must add a page, ' ...
+        'section, and either a graph or a table.']);
+assert(length(o.pages{end}.sections) > 0, ...
+       ['@report.addSeries: Before adding a series, you must add a section and ' ...
+        'either a graph or a table']);
+assert(length(o.pages{end}.sections.elements) > 0, ...
+       ['@report.addSeries: Before adding a series, you must add ' ...
+        'either a graph or a table']);
 assert(isa(o.pages{end}.sections{end}.elements{end}, 'graph') || ...
        isa(o.pages{end}.sections{end}.elements{end}, 'report_table'), ...
        '@report.addSeries: you can only add a series to a report_table or graph object');
diff --git a/src/@report/addTable.m b/src/@report/addTable.m
index 4b1f8c0..8a0e125 100644
--- a/src/@report/addTable.m
+++ b/src/@report/addTable.m
@@ -12,7 +12,7 @@ function o = addTable(o, varargin)
 % SPECIAL REQUIREMENTS
 %   none
 
-% Copyright (C) 2013-2014 Dynare Team
+% Copyright (C) 2013-2015 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -29,6 +29,10 @@ function o = addTable(o, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+assert(length(o.pages) > 0, ...
+       '@report.addTable: Before adding a table, you must add a page and a section.');
+assert(length(o.pages{end}.sections) > 0, ...
+       '@report.addTable: Before adding a table, you must add a section.');
 o.pages{end}.sections{end} = ...
     o.pages{end}.sections{end}.addTable(varargin{:});
 end
diff --git a/src/@report/addVspace.m b/src/@report/addVspace.m
index f4ca186..4e01c86 100644
--- a/src/@report/addVspace.m
+++ b/src/@report/addVspace.m
@@ -12,7 +12,7 @@ function o = addVspace(o, varargin)
 % SPECIAL REQUIREMENTS
 %   none
 
-% Copyright (C) 2013-2014 Dynare Team
+% Copyright (C) 2013-2015 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -29,6 +29,10 @@ function o = addVspace(o, varargin)
 % You should have received a copy of the GNU General Public License
 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 
+assert(length(o.pages) > 0, ...
+       '@report.addVspace: Before adding a vspace, you must add a page and a section.');
+assert(length(o.pages{end}.sections) > 0, ...
+       '@report.addVspace: Before adding a vspace, you must add a section.');
 o.pages{end}.sections{end} = ...
     o.pages{end}.sections{end}.addVspace(varargin{:});
 end
-- 
GitLab