summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Ohly <patrick.ohly@intel.com>2012-06-05 14:57:32 +0200
committerPatrick Ohly <patrick.ohly@intel.com>2012-06-07 14:16:58 +0200
commit2614666ca2e5846470bc2a53ca17840366f29716 (patch)
tree863b69bcedf308eb253b1fdb7463704981b9a609
parent4c8cf8fa9ffacab6b00549c4170373cf15dddf07 (diff)
command line: better error messages about config problems
Using a config name which refers to a context now triggers a specific error. The operation that cannot be continued is named explicitly: $ ./syncevolution @default [INFO] Configuration "@default" does not refer to a sync peer. [ERROR] Cannot proceed with sync without a configuration. The error message about missing configuration also became better: $ ./syncevolution foo@default [INFO] Configuration "foo@default" does not exist. [ERROR] Cannot proceed with sync without a configuration.
-rw-r--r--src/syncevo/Cmdline.cpp57
-rw-r--r--src/syncevo/SyncContext.cpp22
-rw-r--r--src/syncevo/SyncContext.h4
3 files changed, 68 insertions, 15 deletions
diff --git a/src/syncevo/Cmdline.cpp b/src/syncevo/Cmdline.cpp
index dec84254..31ba8eba 100644
--- a/src/syncevo/Cmdline.cpp
+++ b/src/syncevo/Cmdline.cpp
@@ -3454,11 +3454,40 @@ protected:
CPPUNIT_ASSERT_EQUAL(std::string("GNOME"), keyring.get());
}
+ // Broken command line: treated like a sync, but config doesn't exist.
+ {
+ TestCmdline cmdline("keyring=KDE", "@foobar", NULL);
+ cmdline.doit(false);
+ CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
+ CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"@foobar\" does not refer to a sync peer.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
+ }
+ {
+ TestCmdline cmdline("keyring=KDE", "nosuchpeer@foobar", NULL);
+ cmdline.doit(false);
+ CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
+ CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"nosuchpeer@foobar\" does not exist.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
+ }
+
// empty config prop
{
TestCmdline cmdline("--configure", "@default", NULL);
cmdline.doit();
}
+
+ // Try broken command line again.
+ {
+ TestCmdline cmdline("keyring=KDE", "@foobar", NULL);
+ cmdline.doit(false);
+ CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
+ CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"@foobar\" does not refer to a sync peer.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
+ }
+ {
+ TestCmdline cmdline("keyring=KDE", "nosuchpeer@foobar", NULL);
+ cmdline.doit(false);
+ CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
+ CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"nosuchpeer@foobar\" does not exist.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
+ }
+
{
TestCmdline cmdline("@foobar", NULL);
boost::shared_ptr<SyncContext> context = cmdline.parse();
@@ -3472,9 +3501,6 @@ protected:
{
TestCmdline cmdline("--keyring", "--configure", "@default", NULL);
cmdline.doit();
- }
- {
- TestCmdline cmdline("@foobar", NULL);
boost::shared_ptr<SyncContext> context = cmdline.parse();
CPPUNIT_ASSERT(context);
InitStateTri keyring = context->getKeyring();
@@ -3484,15 +3510,34 @@ protected:
{
TestCmdline cmdline("--keyring=KDE", "--configure", "@default", NULL);
cmdline.doit();
+ boost::shared_ptr<SyncContext> context = cmdline.parse();
+ CPPUNIT_ASSERT(context);
+ InitStateTri keyring = context->getKeyring();
+ CPPUNIT_ASSERT_EQUAL(true, keyring.wasSet());
+ CPPUNIT_ASSERT_EQUAL(InitStateTri::VALUE_STRING, keyring.getValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("KDE"), keyring.get());
}
+
+ // create by setting keyring in @default, then update;
+ // @default not strictly needed
+ rm_r(m_testDir);
{
- TestCmdline cmdline("@foobar", NULL);
+ TestCmdline cmdline("keyring=KDE", "--configure", "@default", NULL);
+ cmdline.doit();
boost::shared_ptr<SyncContext> context = cmdline.parse();
CPPUNIT_ASSERT(context);
InitStateTri keyring = context->getKeyring();
CPPUNIT_ASSERT_EQUAL(true, keyring.wasSet());
CPPUNIT_ASSERT_EQUAL(InitStateTri::VALUE_STRING, keyring.getValue());
- CPPUNIT_ASSERT_EQUAL(std::string("KDE"), keyring.get());
+ }
+ {
+ TestCmdline cmdline("keyring=yes", "--configure", "@default", NULL);
+ cmdline.doit();
+ boost::shared_ptr<SyncContext> context = cmdline.parse();
+ CPPUNIT_ASSERT(context);
+ InitStateTri keyring = context->getKeyring();
+ CPPUNIT_ASSERT_EQUAL(true, keyring.wasSet());
+ CPPUNIT_ASSERT_EQUAL(InitStateTri::VALUE_TRUE, keyring.getValue());
}
// allow sync operation although --keyring was set
@@ -3500,7 +3545,7 @@ protected:
TestCmdline cmdline("keyring=GNOME", "foobar@default", NULL);
cmdline.doit(false);
CPPUNIT_ASSERT_EQUAL(std::string(""), cmdline.m_out.str());
- CPPUNIT_ASSERT_EQUAL(std::string("[ERROR] No configuration for server \"foobar@default\" found.\n[ERROR] cannot proceed without configuration"), cmdline.m_err.str());
+ CPPUNIT_ASSERT_EQUAL(std::string("[INFO] Configuration \"foobar@default\" does not exist.\n[ERROR] Cannot proceed with sync without a configuration."), cmdline.m_err.str());
}
// catch invalid "keyring" value
diff --git a/src/syncevo/SyncContext.cpp b/src/syncevo/SyncContext.cpp
index b625d207..42df0c69 100644
--- a/src/syncevo/SyncContext.cpp
+++ b/src/syncevo/SyncContext.cpp
@@ -2872,12 +2872,18 @@ void SyncContext::setStableRelease(bool isStableRelease)
IsStableRelease = isStableRelease;
}
-void SyncContext::checkConfig() const
+void SyncContext::checkConfig(const std::string &operation) const
{
+ std::string peer, context;
+ splitConfigString(m_server, peer, context);
if (isConfigNeeded() &&
- !exists()) {
- SE_LOG_ERROR(NULL, NULL, "No configuration for server \"%s\" found.", m_server.c_str());
- throwError("cannot proceed without configuration");
+ (!exists() || peer.empty())) {
+ if (peer.empty()) {
+ SE_LOG_INFO(NULL, NULL, "Configuration \"%s\" does not refer to a sync peer.", m_server.c_str());
+ } else {
+ SE_LOG_INFO(NULL, NULL, "Configuration \"%s\" does not exist.", m_server.c_str());
+ }
+ throwError(StringPrintf("Cannot proceed with %s without a configuration.", operation.c_str()));
}
}
@@ -2885,7 +2891,7 @@ SyncMLStatus SyncContext::sync(SyncReport *report)
{
SyncMLStatus status = STATUS_OK;
- checkConfig();
+ checkConfig("sync");
// redirect logging as soon as possible
SourceList sourceList(*this, m_doLogging);
@@ -3895,7 +3901,7 @@ SyncMLStatus SyncContext::handleException()
void SyncContext::status()
{
- checkConfig();
+ checkConfig("status check");
SourceList sourceList(*this, false);
initSources(sourceList);
@@ -3947,7 +3953,7 @@ void SyncContext::status()
void SyncContext::checkStatus(SyncReport &report)
{
- checkConfig();
+ checkConfig("status check");
SourceList sourceList(*this, false);
initSources(sourceList);
@@ -4037,7 +4043,7 @@ bool SyncContext::checkForScriptAbort(SharedSession session)
void SyncContext::restore(const string &dirname, RestoreDatabase database)
{
- checkConfig();
+ checkConfig("restore");
SourceList sourceList(*this, false);
sourceList.accessSession(dirname.c_str());
diff --git a/src/syncevo/SyncContext.h b/src/syncevo/SyncContext.h
index f410ebbf..f5b3dac5 100644
--- a/src/syncevo/SyncContext.h
+++ b/src/syncevo/SyncContext.h
@@ -237,8 +237,10 @@ class SyncContext : public SyncConfig {
/**
* throws error if config is needed and not available
+ *
+ * @param operation a noun describing what is to be done next ("proceed with %s", operation)
*/
- void checkConfig() const;
+ void checkConfig(const std::string &operation) const;
/**
* Sets configuration filters. Currently only used in local sync