Commit ae5805e4 authored by Guido Günther's avatar Guido Günther

Improve error messages on formatting errors

Make it easier for the user to detect misformated replacement strings in
config files and command line options.
parent 6823e519
......@@ -5,6 +5,7 @@ usr/lib/python2.?/dist-packages/gbp/config.py
usr/lib/python2.?/dist-packages/gbp/dch.py
usr/lib/python2.?/dist-packages/gbp/deb/
usr/lib/python2.?/dist-packages/gbp/errors.py
usr/lib/python2.?/dist-packages/gbp/format.py
usr/lib/python2.?/dist-packages/gbp/git/
usr/lib/python2.?/dist-packages/gbp/__init__.py
usr/lib/python2.?/dist-packages/gbp/log.py
......
......@@ -19,6 +19,7 @@
import re
from gbp.git import GitRepository, GitRepositoryError
from gbp.deb.pristinetar import DebianPristineTar
from gbp.format import format_msg
class DebianGitRepository(GitRepository):
"""A git repository that holds the source of a Debian package"""
......@@ -104,7 +105,7 @@ class DebianGitRepository(GitRepository):
>>> DebianGitRepository.version_to_tag("debian/%(version)s", "0:0~0")
'debian/0%0_0'
"""
return format % dict(version=DebianGitRepository._sanitize_version(version))
return format_msg(format, dict(version=DebianGitRepository._sanitize_version(version)))
@staticmethod
def _sanitize_version(version):
......
# vim: set fileencoding=utf-8 :
#
# (C) 2014 Guido Guenther <agx@sigxcpu.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Format a message"""
from gbp.errors import GbpError
def format_msg(msg, args):
"""
Format a strin with the given dict. Be a bit more verbose than
default python about the error cause.
>>> format_msg("%(foo)", {})
Traceback (most recent call last):
...
GbpError: Failed to format %(foo): Missing value 'foo' in {}
>>> format_msg("%(foo)", {'foo': 'bar'})
Traceback (most recent call last):
...
GbpError: Failed to format %(foo) with {'foo': 'bar'}: incomplete format
>>> format_msg("A %(foo)s is a %(bar)s", {'foo': 'dog', 'bar': 'mamal'})
'A dog is a mamal'
"""
try:
return msg % args
except ValueError as e:
raise GbpError("Failed to format %s with %s: %s" % (msg, args, e))
except KeyError as e:
raise GbpError("Failed to format %s: Missing value %s in %s" % (msg, e, args))
......@@ -29,6 +29,7 @@ from gbp.command_wrappers import (Command,
from gbp.config import (GbpOptionParserDebian, GbpOptionGroup)
from gbp.deb.git import (GitRepositoryError, DebianGitRepository)
from gbp.deb.source import DebianSource, DebianSourceError
from gbp.format import format_msg
from gbp.git.vfs import GitVfs
from gbp.deb.upstreamsource import DebianUpstreamSource
from gbp.errors import GbpError
......@@ -603,9 +604,9 @@ def main(argv):
gbp.log.info("Tagging %s as %s" % (source.changelog.version, tag))
if options.retag and repo.has_tag(tag):
repo.delete_tag(tag)
tag_msg=options.debian_tag_msg % dict(
pkg=source.sourcepkg,
version=source.changelog.version)
tag_msg = format_msg(options.debian_tag_msg,
dict(pkg=source.sourcepkg,
version=source.changelog.version))
repo.create_tag(name=tag,
msg=tag_msg,
sign=options.sign_tags, keyid=options.keyid)
......
......@@ -29,6 +29,7 @@ from gbp.deb.changelog import ChangeLog, NoChangeLogError
from gbp.deb.git import (GitRepositoryError, DebianGitRepository)
from gbp.config import GbpOptionParserDebian, GbpOptionGroup, no_upstream_branch_msg
from gbp.errors import GbpError
from gbp.format import format_msg
import gbp.log
from gbp.scripts.common.import_orig import (orig_needs_repack, cleanup_tmp_tree,
ask_package_name, ask_package_version,
......@@ -373,7 +374,7 @@ def main(argv):
epoch = '%s:' % cp.epoch
info = { 'version': "%s%s-1" % (epoch, version) }
env = { 'GBP_BRANCH': options.debian_branch }
gbpc.Command(options.postimport % info, extra_env=env, shell=True)()
gbpc.Command(format_msg(options.postimport, info), extra_env=env, shell=True)()
# Update working copy and index if we've possibly updated the
# checked out branch
current_branch = repo.get_branch()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment