Better error handling, tweaks

pull/418/head
Piero Toffanin 2018-03-29 17:55:19 -04:00
rodzic ae0a0cbf67
commit db81a67c53
6 zmienionych plików z 19 dodań i 7 usunięć

Wyświetl plik

@ -268,7 +268,7 @@ class Map extends React.Component {
handleMapMouseDown(e){ handleMapMouseDown(e){
// Make sure the share popup closes // Make sure the share popup closes
this.shareButton.hidePopup(); if (this.sharePopup) this.shareButton.hidePopup();
} }
render() { render() {

Wyświetl plik

@ -6,7 +6,7 @@ import PluginsAPI from './classes/plugins/API';
// Main is always executed first in the page // Main is always executed first in the page
// We share some objects to avoid having to include it // We share some objects to avoid having to include them
// as a dependency in each component (adds too much space overhead) // as a dependency in each component (adds too much space overhead)
window.ReactDOM = ReactDOM; window.ReactDOM = ReactDOM;
window.React = React; window.React = React;

Wyświetl plik

@ -40,12 +40,13 @@ class TaskVolume(TaskNestedView):
os.path.dirname(os.path.abspath(__file__)), os.path.dirname(os.path.abspath(__file__)),
"calc_volume.grass" "calc_volume.grass"
), context.serialize()).get() ), context.serialize()).get()
if isinstance(output, dict) and 'error' in output: raise GrassEngineException(output['error'])
cols = output.split(':') cols = output.split(':')
if len(cols) == 7: if len(cols) == 7:
return Response({'volume': str(abs(float(cols[6])))}, status=status.HTTP_200_OK) return Response({'volume': str(abs(float(cols[6])))}, status=status.HTTP_200_OK)
else: else:
raise GrassEngineException("Invalid GRASS output: {}".format(output)) raise GrassEngineException(output)
except GrassEngineException as e: except GrassEngineException as e:
return Response({'error': str(e)}, status=status.HTTP_200_OK) return Response({'error': str(e)}, status=status.HTTP_200_OK)

Wyświetl plik

@ -36,6 +36,8 @@ module.exports = class MeasurePopup extends React.Component {
lastCoord.dd.x lastCoord.dd.x
)); ));
console.log(layers);
// Did we select a layer? // Did we select a layer?
if (layers.length > 0){ if (layers.length > 0){
const layer = layers[layers.length - 1]; const layer = layers[layers.length - 1];
@ -95,7 +97,7 @@ module.exports = class MeasurePopup extends React.Component {
<p>Perimeter: {this.props.model.lengthDisplay}</p> <p>Perimeter: {this.props.model.lengthDisplay}</p>
{volume === null && !error && <p>Volume: <i>computing...</i> <i className="fa fa-cog fa-spin fa-fw" /></p>} {volume === null && !error && <p>Volume: <i>computing...</i> <i className="fa fa-cog fa-spin fa-fw" /></p>}
{typeof volume === "number" && <p>Volume: {volume.toFixed("2")} Cubic Meters ({(volume * 35.3147).toFixed(2)} Cubic Feet)</p>} {typeof volume === "number" && <p>Volume: {volume.toFixed("2")} Cubic Meters ({(volume * 35.3147).toFixed(2)} Cubic Feet)</p>}
{error && <p>Volume: <span className="error theme-background-failed">{error}</span></p>} {error && <p>Volume: <span className={"error theme-background-failed " + (error.length > 200 ? 'long' : '')}>{error}</span></p>}
</div>); </div>);
} }
} }

Wyświetl plik

@ -2,4 +2,10 @@
p{ p{
margin: 0; margin: 0;
} }
.error.long{
overflow: scroll;
display: block;
max-height: 200px;
}
} }

Wyświetl plik

@ -8,7 +8,7 @@ from django.db.models import Q
from app.models import Project from app.models import Project
from app.models import Task from app.models import Task
from app.plugins.grass_engine import grass from app.plugins.grass_engine import grass, GrassEngineException
from nodeodm import status_codes from nodeodm import status_codes
from nodeodm.models import ProcessingNode from nodeodm.models import ProcessingNode
from webodm import settings from webodm import settings
@ -82,5 +82,8 @@ def process_pending_tasks():
@app.task @app.task
def execute_grass_script(script, serialized_context = {}): def execute_grass_script(script, serialized_context = {}):
ctx = grass.create_context(serialized_context) try:
return ctx.execute(script) ctx = grass.create_context(serialized_context)
return ctx.execute(script)
except GrassEngineException as e:
return {'error': str(e)}