Giter Club home page Giter Club logo

haxe-exception's People

Contributors

realyuniquename avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bradparks

haxe-exception's Issues

haxe.Exception has no fields thrown

I am getting this error haxe.Exception has no field thrown

I extended it like this:

class GraphQLError extends haxe.Exception {
	/**
	 * An array of { line, column } locations within the source GraphQL document
	 * which correspond to this error.
	 *
	 * Errors during validation often contain multiple locations, for example to
	 * point out two things with the same name. Errors during execution include a
	 * single location, the field which produced the error.
	 *
	 * Enumerable, and appears in the result of JSON.stringify().
	 */
	var locations:ReadOnlyArray<SourceLocation>;

	/**
	 * An array describing the JSON-path into the execution response which
	 * corresponds to this error. Only included for errors during execution.
	 *
	 * Enumerable, and appears in the result of JSON.stringify().
	 */
	var path:ReadOnlyArray<Any>;

	/**
	 * An array of GraphQL AST Nodes corresponding to this error.
	 */
	var nodes:ReadOnlyArray<ASTNode>;

	/**
	 * The source GraphQL document for the first location of this error.
	 *
	 * Note that if this Error represents more than one node, the source may not
	 * represent nodes after the first node.
	 */
	var source:Source;

	/**
	 * An array of character offsets within the source GraphQL document
	 * which correspond to this error.
	 */
	var positions:ReadOnlyArray<Int>;

	/**
	 * The original error thrown from a field resolver during execution.
	 */
	var originalError:haxe.Exception;

	/**
	 * Extension fields to add to the formatted error.
	 */
	var extensions:Dynamic;

	public function new(message:String, ?nodes:ReadOnlyArray<ASTNode>, ?source:Source, ?positions:ReadOnlyArray<Int>, ?path:ReadOnlyArray<Any>,
			?originalError:haxe.Exception, ?extensions:Dynamic) {
		this.nodes = nodes;

		if (source == null && nodes != null)
			this.source = nodes[0].loc != null ? nodes[0].loc.source : new Source("");

		if (positions == null && nodes != null) {
			this.positions = reduce(nodes, (list : Array<Int>, node : ASTNode) -> {
				if (node.loc != null) {
					list.push(node.loc.start);
				}
				return list;
			}, []);
		}
		if (positions != null && positions.length == 0) {
			this.positions = null;
		}

		if (positions != null && source != null) {
			this.locations = positions.map((pos) -> SourceLocation.getLocation(source, pos));
		} else if (nodes != null) {

			this.locations = reduce(nodes, (list : Array<SourceLocation>, node : ASTNode) -> {
				if (node.loc != null) {
					list.push(SourceLocation.getLocation(node.loc.source, node.loc.start));
				}
				return list;
			}, []);
		}

		super(message);
	}

	override public function toString():String {
		var s = super.toString();
		return s + ":" + printError(this);
	}

	public static function printError(error:GraphQLError) {
		var output = "";

		if (error.nodes != null) {
			for (node in error.nodes) {
				if (node.loc != null) {
					output += '\n\n' + SourceLocation.printLocation(node.loc);
				}
			}
		} else if (error.source != null && error.locations != null) {
			for (location in error.locations) {
				output += '\n\n' + SourceLocation.printSourceLocation(error.source, location);
			}
		}

		return output;
	}

	public function reduce<K, T>(arr:ReadOnlyArray<K>, callback:(acc:Array<T>, v:K) -> Array<T>, accumulator:Array<T>) {
		for (i in 0...arr.length) {
			accumulator = callback(accumulator, arr[i]);
		}
		return accumulator;
	}
}


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.