Skip to content

Commit a84b181

Browse files
author
Aaron Leung
committed
Catching a top-level 'file not found' error.
1 parent c06402f commit a84b181

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

document.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ namespace Sass {
6565
tmp = folder + non_partial_filename;
6666
path_str = tmp.c_str();
6767
// if we still can't find the file, then throw an error
68-
if (stat(path_str, &st) == -1 || S_ISDIR(st.st_mode))
68+
if (stat(path_str, &st) == -1 || S_ISDIR(st.st_mode)) {
6969
throw path;
70+
}
7071
}
7172
}
7273
}

sass_interface.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,9 @@ extern "C" {
101101
int sass_compile_file(sass_file_context* c_ctx)
102102
{
103103
using namespace Sass;
104+
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path, c_ctx->options.source_comments);
104105
try {
105-
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path, c_ctx->options.source_comments);
106-
// Document doc(c_ctx->input_path, 0, cpp_ctx);
107-
// string path_string(c_ctx->options.image_path);
108-
// path_string = "'" + path_string + "/";
109-
// cpp_ctx.image_path = c_ctx->options.image_path;
110106
Document doc(Document::make_from_file(cpp_ctx, string(c_ctx->input_path)));
111-
// cerr << "MADE A DOC AND CONTEXT OBJ" << endl;
112-
// cerr << "REGISTRY: " << doc.context.registry.size() << endl;
113107
c_ctx->output_string = process_document(doc, c_ctx->options.output_style);
114108
c_ctx->error_message = 0;
115109
c_ctx->error_status = 0;
@@ -134,6 +128,29 @@ extern "C" {
134128
c_ctx->output_string = 0;
135129
c_ctx->error_message = msg_str;
136130
}
131+
catch(string& bad_path) {
132+
for (vector<string>::iterator path = cpp_ctx.include_paths.begin(); path < cpp_ctx.include_paths.end(); ++path) {
133+
try {
134+
Document doc(Document::make_from_file(cpp_ctx, *path + string(c_ctx->input_path)));
135+
c_ctx->output_string = process_document(doc, c_ctx->options.output_style);
136+
c_ctx->error_message = 0;
137+
c_ctx->error_status = 0;
138+
return 0;
139+
}
140+
catch (string& bad_path) {
141+
// continue looping
142+
}
143+
}
144+
// couldn't find the specified file in the include paths; report an error
145+
stringstream msg_stream;
146+
msg_stream << "error reading file \"" << bad_path << "\"" << endl;
147+
string msg(msg_stream.str());
148+
char* msg_str = (char*) malloc(msg.size() + 1);
149+
strcpy(msg_str, msg.c_str());
150+
c_ctx->error_status = 1;
151+
c_ctx->output_string = 0;
152+
c_ctx->error_message = msg_str;
153+
}
137154
// TO DO: CATCH EVERYTHING ELSE
138155
return 0;
139156
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy