SFTtech/openage

More informative `Exception`/Error messages in converter

已關閉

#1,344 建立於 2020年12月18日

 (13 則留言) (0 個反應) (0 位負責人)Python (1,135 個分叉)batch import
area: assetsgood first issueimprovementlang: python

倉庫指標

星標
 (12,130 顆星)
PR 合併指標
 (平均合併 9天 23小時) (30 天內合併 1 個 PR)

描述

Required skills: Python

Difficulty: Medium

In AoE2's .dat format most associations and assignments of properties are done by IDs (e.g. unit has ability with ID X). The openage converter uses these IDs to lookup the associated openage API property and then map the values from AoE2's .dat structure to the corresponding API object's member values. In short, every property from AoE2 needs to be manually mapped to an openage API property. As such, most of the runtime errors are actually lookup errors (usually Python's KeyError) that occur when an AoE2 property was not mapped to an openage API property.

The goal of this task is to make these errors more informative by catching the generic KeyError from Python and re-raising it with a better message. For example, we can improve the error message by specifying:

  • Context of the property (i.e. the property is: ability, resource, unit, tech, ...)
  • Data type that is looked up (function, object, string, other ID, ...)

Example

generic message:

File "openage/convert/processor/conversion/de2/tech_subprocessor.py", line 276, in resource_modify_effect
    upgrade_func = DE2TechSubprocessor.upgrade_resource_funcs[resource_id]
KeyError: 208

better message:

File "openage/convert/processor/conversion/de2/tech_subprocessor.py", line 276, in resource_modify_effect
    upgrade_func = DE2TechSubprocessor.upgrade_resource_funcs[resource_id]
KeyError: No subprocessor function found for handling upgrade of civ resource: 208

Use try-except statement where these lookups could be thrown. Remember to use raise ... from to preserve the stack trace of the initial KeyError.

Further reading:

貢獻者指南