var name;

function loadStyleSheet(sheet, callback, reload, remaining) {
    var sheetName = name.slice(0, name.lastIndexOf('/') + 1) + sheet.href;
    var input = readFile(sheetName);
    var parser = new less.Parser({
        paths: [sheet.href.replace(/[\w\.-]+$/, '')]
    });
    parser.parse(input, function (e, root) {
        if (e) {
            print("Error: " + e.toSource());
            quit(1);
        }
        callback(null, root, sheet, { local: false, lastModified: 0, remaining: remaining });
    });

    // callback({}, sheet, { local: true, remaining: remaining });
}

function writeFile(filename, content) {
    var fstream = new java.io.FileWriter(filename);
    var out = new java.io.BufferedWriter(fstream);
    out.write(content);
    out.close();
}

// Command line integration via Rhino
(function (args) {
    name = args[0];
    var output = args[1];

    if (!name) {
        print('No files present in the fileset; Check your pattern match in build.xml');
        quit(1);
    }
    path = name.split("/");path.pop();path=path.join("/")

    var input = readFile(name);

    if (!input) {
        print('lesscss: couldn\'t open file ' + name);
        quit(1);
    }

    var result;
    var parser = new less.Parser();
    parser.parse(input, function (e, root) {
        if (e) {
            quit(1);
        } else {
            result = root.toCSS();
            if (output) {
                writeFile(output, result);
                print("Written to " + output);
            } else {
                print(result);
            }
            quit(0);
        }
    });
    print("done");
}(arguments));

@@ -352,38 +352,33 @@
     
-print(%22Error: %22 + e.toSource()
+return error(e, sheetName
 );%0A 
@@ -388,31 +388,28 @@
     
+%7D%0A
     
-quit(1);%0A    
+    try %7B%0A
     
-%7D%0A
     
@@ -425,12 +425,9 @@
 ack(
-null
+e
 , ro
@@ -503,75 +503,71 @@
     
-%7D);%0A%0A
     
-// callback(%7B%7D, sheet, %7B local: true, remaining: remaining
+%7D catch(e) %7B%0A            error(e, sheetName);%0A        %7D%0A   
  %7D);
@@ -1178,17 +1178,16 @@
 ;%0A    %7D%0A
-%0A
     var 
@@ -1194,16 +1194,30 @@
 result;%0A
+    try %7B%0A    
     var 
@@ -1240,24 +1240,28 @@
 s.Parser();%0A
+    
     parser.p
@@ -1293,32 +1293,36 @@
 root) %7B%0A        
+    
 if (e) %7B%0A       
@@ -1306,32 +1306,68 @@
        if (e) %7B%0A
+                error(e, name);%0A    
             quit
@@ -1371,32 +1371,36 @@
 uit(1);%0A        
+    
 %7D else %7B%0A       
@@ -1384,32 +1384,36 @@
        %7D else %7B%0A
+    
             resu
@@ -1439,24 +1439,28 @@
             
+    
 if (output) 
@@ -1457,24 +1457,28 @@
  (output) %7B%0A
+    
             
@@ -1520,24 +1520,28 @@
             
+    
 print(%22Writt
@@ -1563,32 +1563,36 @@
 t);%0A            
+    
 %7D else %7B%0A       
@@ -1576,32 +1576,36 @@
        %7D else %7B%0A
+    
                 
@@ -1623,34 +1623,40 @@
 t);%0A            
-%7D%0A
+    %7D%0A  
             quit
@@ -1647,24 +1647,26 @@
             
+  
 quit(0);%0A   
@@ -1674,22 +1674,30 @@
     
+    
 %7D%0A    
+    
 %7D);%0A    
 prin
@@ -1696,34 +1696,767 @@
     
-print(%22done%22);%0A%7D(arguments));%0A
+%7D%0A    catch(e) %7B%0A        error(e, name);%0A        quit(1);%0A    %7D%0A    print(%22done%22);%0A%7D(arguments));%0A%0Afunction error(e, filename) %7B%0A%0A    var content = %22Error : %22 + filename + %22%5Cn%22;%0A    %0A    filename = e.filename %7C%7C filename;%0A    %0A    if (e.message) %7B%0A        content += e.message + %22%5Cn%22;%0A    %7D%0A%0A    var errorline = function (e, i, classname) %7B%0A        if (e.extract%5Bi%5D) %7B%0A            content += %0A                String(parseInt(e.line) + (i - 1)) + %0A                %22:%22 + e.extract%5Bi%5D + %22%5Cn%22;%0A        %7D%0A    %7D;%0A%0A    if (e.stack) %7B%0A        content += e.stack;%0A    %7D else if (e.extract) %7B%0A        content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':%5Cn';%0A        errorline(e, 0);%0A        errorline(e, 1);%0A        errorline(e, 2);%0A    %7D%0A   print(content);%0A%7D

Make rhino error support better